Page 1 of 1

Array refusing to output

Posted: Tue Feb 08, 2005 6:44 am
by Linkjames
Hi, I am constructing a simple php program to take test result files, extract the bits I need, and output them all into a single CVS file. So far, I can harvest the data I need, but I cannot display it (I'm displaying it so I can check it before I output to a file)

Anyway, this is the code:

Code: Select all

<?php

include 'group.php';
include 'time.php';
	

//print_r(array_values($time1final));
//print_r(array_values($time2final));
print_r(array_values($groupfinal));


$count = count($groupfinal);
$timekey = "0";
while($timekey <= $count )&#123;
	echo $groupfinal&#1111;$timekey];
	echo $time1final&#1111;$timekey];
	echo $time2final&#1111;$timekey];
	$timekey++;
&#125;



/*foreach ($groupfinal as $key => $value)&#123;
	//echo $value;
	echo $time1final&#1111;$timekey];
	//echo $time2final&#1111;$timekey];
	echo "\r\n";
	$timekey++;
&#125;*/
//print_r(array_values($time1final));

?>
And this is the output I get:

Code: Select all

Content-type: text/html
X-Powered-By: PHP/4.3.10

Array
(
    &#1111;0] => db74       

    &#1111;1] => ic74       

    &#1111;2] => ix74       

    &#1111;3] => lb74       

    &#1111;4] => nc74       

    &#1111;5] => rl74       

    &#1111;6] => rw74       

    &#1111;7] => sg74       

    &#1111;8] => sq74       

    &#1111;9] => st74       

    &#1111;10] => th74       

    &#1111;11] => db85       

)
<br />
<b>Notice</b>:  Undefined index:  0 in <b>c:\php\run.php</b> on line <b>14</b><br />
<br />
<b>Notice</b>:  Undefined index:  0 in <b>c:\php\run.php</b> on line <b>15</b><br />
<br />
<b>Notice</b>:  Undefined index:  0 in <b>c:\php\run.php</b> on line <b>16</b><br />
<br />
<b>Notice</b>:  Undefined offset:  1 in <b>c:\php\run.php</b> on line <b>14</b><br />
<br />
<b>Notice</b>:  Undefined offset:  1 in <b>c:\php\run.php</b> on line <b>15</b><br />
<br />
<b>Notice</b>:  Undefined offset:  1 in <b>c:\php\run.php</b> on line <b>16</b><br />
<br />
<b>Notice</b>:  Undefined offset:  2 in <b>c:\php\run.php</b> on line <b>14</b><br />
<br />
<b>Notice</b>:  Undefined offset:  2 in <b>c:\php\run.php</b> on line <b>15</b><br />
<br />
<b>Notice</b>:  Undefined offset:  2 in <b>c:\php\run.php</b> on line <b>16</b><br />
<br />
<b>Notice</b>:  Undefined offset:  3 in <b>c:\php\run.php</b> on line <b>14</b><br />
<br />
<b>Notice</b>:  Undefined offset:  3 in <b>c:\php\run.php</b> on line <b>15</b><br />
<br />
<b>Notice</b>:  Undefined offset:  3 in <b>c:\php\run.php</b> on line <b>16</b><br />
<br />
<b>Notice</b>:  Undefined offset:  4 in <b>c:\php\run.php</b> on line <b>14</b><br />
<br />
<b>Notice</b>:  Undefined offset:  4 in <b>c:\php\run.php</b> on line <b>15</b><br />
<br />
<b>Notice</b>:  Undefined offset:  4 in <b>c:\php\run.php</b> on line <b>16</b><br />
<br />
<b>Notice</b>:  Undefined offset:  5 in <b>c:\php\run.php</b> on line <b>14</b><br />
<br />
<b>Notice</b>:  Undefined offset:  5 in <b>c:\php\run.php</b> on line <b>15</b><br />
<br />
<b>Notice</b>:  Undefined offset:  5 in <b>c:\php\run.php</b> on line <b>16</b><br />
<br />
<b>Notice</b>:  Undefined offset:  6 in <b>c:\php\run.php</b> on line <b>14</b><br />
<br />
<b>Notice</b>:  Undefined offset:  6 in <b>c:\php\run.php</b> on line <b>15</b><br />
<br />
<b>Notice</b>:  Undefined offset:  6 in <b>c:\php\run.php</b> on line <b>16</b><br />
<br />
<b>Notice</b>:  Undefined offset:  7 in <b>c:\php\run.php</b> on line <b>14</b><br />
<br />
<b>Notice</b>:  Undefined offset:  7 in <b>c:\php\run.php</b> on line <b>15</b><br />
<br />
<b>Notice</b>:  Undefined offset:  7 in <b>c:\php\run.php</b> on line <b>16</b><br />
<br />
<b>Notice</b>:  Undefined offset:  8 in <b>c:\php\run.php</b> on line <b>14</b><br />
<br />
<b>Notice</b>:  Undefined offset:  8 in <b>c:\php\run.php</b> on line <b>15</b><br />
<br />
<b>Notice</b>:  Undefined offset:  8 in <b>c:\php\run.php</b> on line <b>16</b><br />
<br />
<b>Notice</b>:  Undefined offset:  9 in <b>c:\php\run.php</b> on line <b>14</b><br />
<br />
<b>Notice</b>:  Undefined offset:  9 in <b>c:\php\run.php</b> on line <b>15</b><br />
<br />
<b>Notice</b>:  Undefined offset:  9 in <b>c:\php\run.php</b> on line <b>16</b><br />
<br />
<b>Notice</b>:  Undefined offset:  10 in <b>c:\php\run.php</b> on line <b>14</b><br />
<br />
<b>Notice</b>:  Undefined offset:  10 in <b>c:\php\run.php</b> on line <b>15</b><br />
<br />
<b>Notice</b>:  Undefined offset:  10 in <b>c:\php\run.php</b> on line <b>16</b><br />
<br />
<b>Notice</b>:  Undefined offset:  11 in <b>c:\php\run.php</b> on line <b>14</b><br />
<br />
<b>Notice</b>:  Undefined offset:  11 in <b>c:\php\run.php</b> on line <b>15</b><br />
<br />
<b>Notice</b>:  Undefined offset:  11 in <b>c:\php\run.php</b> on line <b>16</b><br />
<br />
<b>Notice</b>:  Undefined offset:  12 in <b>c:\php\run.php</b> on line <b>14</b><br />
<br />
<b>Notice</b>:  Undefined offset:  12 in <b>c:\php\run.php</b> on line <b>15</b><br />
<br />
<b>Notice</b>:  Undefined offset:  12 in <b>c:\php\run.php</b> on line <b>16</b><br />
The arrays are created in the include and I have checked they all work (
As you can see, the arrays have been commented out where I tested them)

Anyway, I canoot understand why I am getting these undefined index errors, as the array clearly displays before I run individual elements. Or perhaps I misunderstand the meaning of the error? Eitherway, if anyone can spot what I have done wrong, I would be very grateful if you could point it out.

Link

Posted: Tue Feb 08, 2005 7:01 am
by JayBird
This wont solve your issue, but just a little note. I would do this

Code: Select all

for($timekey = 0; $timekey <= count($groupfinal); $timekey++)&#123; 
   echo $groupfinal&#1111;$timekey]; 
   echo $time1final&#1111;$timekey]; 
   echo $time2final&#1111;$timekey]; 
&#125;

Posted: Tue Feb 08, 2005 7:24 am
by Linkjames
Cheers. Will change it to that.

Anyone else? It should flipping well work as far as I can tell >:|

;)

Link

Posted: Tue Feb 08, 2005 8:01 am
by feyd
<= count is a logic error. It should be < only.

It would appear that you are using named indices, and not numeric ones.