Incremental $_POST var names

I’m building the PayPal IPN script but the POST variables PayPal sends have number suffixes for the cart items, eg.

$_POST['option_selection1_1']
$_POST['option_selection1_2']
$_POST['option_selection1_3']

I would normally (in PHP) do a WHILE loop like this:

	$loopy = 0;
	do { // $loopy < $_POST['num_cart_items']
		$loopy++;
	// CODE HERE
	} while ($loopy < $_POST['num_cart_items']);

and then refer to the variables like this:

$_POST['option_selection1_' . $loopy]

How can I achieve this within an API script?

I’m using Set Value to start at zero, then do a WHILE var1 < $_POST['num_cart_items']

but how can I then reference the POST variables appending var1 to the variable name.

I hope I’ve explained this clearly enough.

You wish :slight_smile:

I'm failing to understand if this is a PHP or a NodeJS project, so I'm assuming NodeJS. If there's any difference between NodeJS and PHP is the string concatenation (PHP uses a dot, JavaScript uses a plus)

Edit: Forgot to increment globalLoopy inside the While loop, make sure you do it

1 Like

Brilliant. Thanks @Apple. That looks like exactly what I needed to know.

This one is a PHP project but I don't think it matters in this instance.

I'll let you know how I get on. Thanks again.

1 Like

Thanks again @Apple. Works perfectly. :slight_smile: