开发者

Foreach loop inside a php class?

I have a very simple task yet it keeps failing.

I want to have a function inside a class and the param that you pass into the function will be an array. All the function has to do is echo back the contents of the array.

Echoing out all the variables in for example the $_POST array is very easy to achieve with a foreach loop. However, it does not work in my class.

This was a very generic explanation. I you need more details please ask.

public function check_if_filled($array){ 
    foreach($array as $key->$value){ 
 开发者_如何学C       echo $key . " : " . $value;
    } 
}

any advice why it gives me this error

Notice: Undefined variable: value in (my page) on line 117

Fatal error: Cannot access empty property in (my page) on line 117


You used the wrong type of arrow in the foreach loop.

foreach($array as $key->$value)

should be

foreach($array as $key=>$value) 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜