Reputation: 21
I have an array called $worker
the array consists of only strings, each of which has multiple lines.
if I do
var_dump($worker);
it displays all the information, but do
for($i=0,$size=sizeof($worker);$i<$size;++$i)
{
echo $worker[i];
}
I end up with nothing on the page.
I'm very new to php, so sorry if this is a noob question: how do I get the information in the array to print to the screen correctly?
Upvotes: 2
Views: 2988
Reputation: 176
You're missing the '$' for your '$i' variable inside the for
loop.
It's a good idea to turn on error reporting while developing in PHP: http://php.net/manual/en/function.error-reporting.php
This is the conventional syntax for for
loops in PHP:
for ($i=0, $c=count($worker); $i<$c; $i++) {
echo $worker[$i];
}
Upvotes: 5
Reputation: 453
for($i=0,$size=count($worker);$i<$size;++$i)
{
echo $worker[$i];
}
You forgot '$' int echo $worker[$i];
Upvotes: 3
Reputation: 2398
You forgot the dollar sign before i in $worker[$i]
.
-edit-: Removed the second part, maybe I'm too tired :)
Upvotes: 1