开发者

var_dump displays text, but echo does not

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($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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜