dependant incremental php variables

blondegeek

Baseband Member
Messages
23
Hello! I'm trying to code up a handler for PayPal's IPN (Instant Payment Notification) feature. Since I'm going to be recieving information from a shopping cart and therefore multiple items, I need to make sure that I have a specific number of variables ready to accept the variables from PayPal. For example, if there are 4 different items from the shopping cart I need a variable to accept each:

Code:
$num_cart_items =$_POST['num_cart_items']

So if num_cart_items equals 4 then I need:

Code:
$item_name1 = $_POST['item_name1'];
$item_name2 = $_POST['item_name2'];
$item_name3 = $_POST['item_name3'];
$item_name4 = $_POST['item_name4'];

How do I make this so it will add as many number specifc variables needed depending on the number of items in the shopping cart?

Thanks!
 
use another variable to keep track of the amount iof items in the cart, and then pull the variables from the car into an array

<?php
$total = $_POST['totalitems'];

for ($x=1;$<=total;$x++)
{
$items[$x] = $_POST['item_name' . $x];
}
?>
 
Back
Top Bottom