wemustdesign Posted March 6, 2010 Share Posted March 6, 2010 I am using the Paypal ipn to add bought products to my database. So I have posted my products to Pyapl fine. I am having trouble getting the variables dy7namically in the IPN. I can do it manually fine like this: $item_number1 = $_POST['item_number1']; $item_number2 = $_POST['item_number2']; .................... I need to dynamically create the above. I thought the while loop below would work but I am not sure if this is how you would do this, or if I have the correct syntax: $dc=1; while($dc <= $num_cart_items){ echo "$item_number$dc = $_POST['item_number$dc']"; $dc++; Quote Link to comment https://forums.phpfreaks.com/topic/194323-dynamically-get-_post/ Share on other sites More sharing options...
jskywalker Posted March 6, 2010 Share Posted March 6, 2010 <?php $a['item_number1']='1111'; $a['item_number2']='2222'; $a['item_number3']='3333'; $a['item_number4']='4444'; $dc='1'; while($dc <=4) { ${"item_number{$dc}"} = $a["item_number$dc"]; $dc++; } print $item_number1."<br>\n"; print $item_number2."<br>\n"; print $item_number3."<br>\n"; print $item_number4."<br>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/194323-dynamically-get-_post/#findComment-1022269 Share on other sites More sharing options...
Zane Posted March 6, 2010 Share Posted March 6, 2010 This should do the trick. for($dc = 1; $dc $theIndex = "item_number" . $dc; echo ${$theIndex} = $_POST[$theIndex]; } Quote Link to comment https://forums.phpfreaks.com/topic/194323-dynamically-get-_post/#findComment-1022272 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.