var_dump displays text, but echo does not
I have an array called $worker
if I do
var_dump($worker);
it displays all the information, but do
for($i=0,$size=sizeof($work开发者_开发百科er);$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?
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];
}
for($i=0,$size=count($worker);$i<$size;++$i)
{
echo $worker[$i];
}
You forgot '$' int echo $worker[$i];
You forgot the dollar sign before i in $worker[$i]
.
-edit-: Removed the second part, maybe I'm too tired :)
精彩评论