Jump to content

[SOLVED] Use if to find value inside for loop


KeeganWolf

Recommended Posts

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?

 

 

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!";
   }

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.