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)
精彩评论