Jump to content

Dynamic Variable incrementation loop


l95theses

Recommended Posts

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

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;

}

?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.