- Joined
- Aug 15, 2008
- Messages
- 489
- Reaction score
- 43
Solved! I had to use array_map to make it work.
___________________________________________________________________________________________________________________
I'm using the PayPal IPN to receive name and quantity for each item that has been bought and add them to database.
I want them to be in 1 row, like "1x Item name, 2x Other item, 1x Another item", so I created an array and added items to it with for loop.
How can I destruct this array and make a variable $allproducts that has the items as "1x Item name, 2x Other item, 1x Another item"?
PHP:
$products_implode = implode(" ", array_map(function ($entry) { return $entry['amount'].'x '.$entry['name'].'<br />'; }, $products));
I'm using the PayPal IPN to receive name and quantity for each item that has been bought and add them to database.
I want them to be in 1 row, like "1x Item name, 2x Other item, 1x Another item", so I created an array and added items to it with for loop.
PHP:
$num_cart_items = $_POST['num_cart_items'];
$products= array();
for($i = 1; $i <= $num_cart_items; $i++) {
$products[] = array('name'=>$_POST['item_name' . $i], 'amount'=>$_POST['quantity' . $i]);
}
How can I destruct this array and make a variable $allproducts that has the items as "1x Item name, 2x Other item, 1x Another item"?
Last edited:

