KeeganWolf Posted May 29, 2009 Share Posted May 29, 2009 With any variation, I cannot seem to get this to work. I'm trying to find a value inside of an array, and use an if statement that when the value is found, to echo. The code looks like it should work. $count = count($data); for ($i = 1; $i < $count; $i++) { $data[$i][60] = $data[$i][11] + $data[$i][14] + $data[$i][17] + $data[$i][20] + $data[$i][23] + $data[$i][26] + $data[$i][29] + $data[$i][32] + $data[$i][35] + $data[$i][38]; $data[$i][61] = $data[$i][11] + $data[$i][26]; $data[$i][62] = $data[$i][14] + $data[$i][29]; $data[$i][63] = $data[$i][17] + $data[$i][32]; $data[$i][64] = $data[$i][20] + $data[$i][35]; $data[$i][65] = $data[$i][23] + $data[$i][38]; //find the PLU $plu = ($data[$j][2]); $numsold = intval($data[$j][60]); $numsoldk = intval($data[$j][61]); $numsolds = intval($data[$j][62]); $numsoldm = intval($data[$j][63]); $numsoldl = intval($data[$j][64]); $numsoldx = intval($data[$j][65]); if ($data[$j][2] == 4) { echo "Woooooooot!"; } echo 'You have sold ', $numsold,' of this product -> ',$data[$i][3], ' with the PLU#'; echo $plu, '<br />'; echo 'You have sold ', $data[$i][61] ,' of this product k-> ',$data[$i][3], ' with the PLU#'; echo $data[$i][2], '<br />'; echo 'You have sold ', $data[$i][62] ,' of this product s-> ',$data[$i][3], ' with the PLU#'; echo $data[$i][2], '<br />'; echo 'You have sold ', $data[$i][63] ,' of this product m-> ',$data[$i][3], ' with the PLU#'; echo $data[$i][2], '<br />'; echo 'You have sold ', $data[$i][64] ,' of this product l-> ',$data[$i][3], ' with the PLU#'; echo $data[$i][2], '<br />'; echo 'You have sold ', $data[$i][65] ,' of this product x-> ',$data[$i][3], ' with the PLU#'; echo $data[$i][2], '<br />'; } echo 'You have sold ', $i, ' types of items'; The output displays correctly for everything else, but the if statement will never run. $data[$i][2] is a small integer, and I have tried with and without intval. Any ideas? Link to comment https://forums.phpfreaks.com/topic/160145-solved-use-if-to-find-value-inside-for-loop/ Share on other sites More sharing options...
Ken2k7 Posted May 29, 2009 Share Posted May 29, 2009 Is $j defined anywhere? Where did $j come from in this block of code? <?php $plu = ($data[$j][2]); $numsold = intval($data[$j][60]); $numsoldk = intval($data[$j][61]); $numsolds = intval($data[$j][62]); $numsoldm = intval($data[$j][63]); $numsoldl = intval($data[$j][64]); $numsoldx = intval($data[$j][65]); if ($data[$j][2] == 4) { echo "Woooooooot!"; } Link to comment https://forums.phpfreaks.com/topic/160145-solved-use-if-to-find-value-inside-for-loop/#findComment-844916 Share on other sites More sharing options...
KeeganWolf Posted May 29, 2009 Author Share Posted May 29, 2009 wow. I feel stupid lol Thanks Ken Link to comment https://forums.phpfreaks.com/topic/160145-solved-use-if-to-find-value-inside-for-loop/#findComment-844924 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.