l95theses Posted July 11, 2007 Share Posted July 11, 2007 I'm trying to make this code dynamic so that I can decrease it by the number of items in the inventory, this is the static formula to that works, but I don't want to have to add this every time I have another item to check for. Help me to dynamically subtract one from the amount of items. PLEASE!!! thanks... if ( $$itemg == $citem1_array[0] ) { echo "$citem1_array[1] - $citem1_array[2]"; echo "<br>"; } if ( $$itemg == $citem2_array[0] ) { echo "$citem2_array[1] - $citem2_array[2]"; echo "<br>"; } if ( $$itemg == $citem3_array[0] ) { echo "$citem3_array[1] - $citem3_array[2]"; echo "<br>"; } Link to comment https://forums.phpfreaks.com/topic/59532-dynamic-variable-incrementation-loop/ Share on other sites More sharing options...
teng84 Posted July 11, 2007 Share Posted July 11, 2007 i dont understand but may be this for ($x=0;$x<=count(fut here the array); $x++) { //now put the x on the counter $array[$x]; and if you want the $xto be 1 or 2 just $array[$x+1]; } i dont know maybe is that what you mean Link to comment https://forums.phpfreaks.com/topic/59532-dynamic-variable-incrementation-loop/#findComment-295824 Share on other sites More sharing options...
l95theses Posted July 11, 2007 Author Share Posted July 11, 2007 im trying to change the citem in increments untill all of the citems have been checked, so that every item that i have in inventory is gone through, here is the full php doc. <html><body><embed src=retail.swf height=100% width=100% wmode=transparent></body></html> <?php $citem2_array[0] = "1"; $citem2_array[1] = "Zephyrhills Spring water"; $citem2_array[2] = "$1.79"; $citem1_array[0] = "2"; $citem1_array[1] = "Kombucha Wonder Drink"; $citem1_array[2] = "$1.59"; $citem3_array[0] = "3"; $citem3_array[1] = "Chocolate Rice Dream Drink"; $citem3_array[2] = "$1.88"; $totalinv = 4; $totalitems = $_POST['n1']; $item1 = $_POST['item1']; $item2 = $_POST['item2']; $item3 = $_POST['item3']; $item4 = $_POST['item4']; $item5 = $_POST['item5']; $item6 = $_POST['item6']; $item7 = $_POST['item7']; $item8 = $_POST['item8']; $item9 = $_POST['item9']; $item10 = $_POST['item10']; $item11 = $_POST['item11']; $item12 = $_POST['item12']; $item13 = $_POST['item13']; $item14 = $_POST['item14']; $item15 = $_POST['item15']; $item16 = $_POST['item16']; $item17 = $_POST['item17']; $item18 = $_POST['item18']; $item19 = $_POST['item19']; $item20 = $_POST['item20']; $itemnum = 0; while ( $itemnum < 20 ) { if ( $$itemg == $citem1_array[0] ) { echo "$citem1_array[1] - $citem1_array[2]"; echo "<br>"; } if ( $$itemg == $citem2_array[0] ) { echo "$citem2_array[1] - $citem2_array[2]"; echo "<br>"; } if ( $$itemg == $citem3_array[0] ) { echo "$citem3_array[1] - $citem3_array[2]"; echo "<br>"; } $itemnum = $itemnum + 1; $itemg = "item" . $itemnum; } ?> Link to comment https://forums.phpfreaks.com/topic/59532-dynamic-variable-incrementation-loop/#findComment-295839 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.