iwato Posted December 23, 2010 Share Posted December 23, 2010 QUESTION: When the foreach-statement runs PHP responds with an error stating that $info is undefined. Why? <?php class Student { $info = array( 'first_name' => 'John', 'last_name' => 'Smith', 'email' => 'john@smith.com'); public function listStudentInfo() { foreach ($this->$info as $key => $value) { echo "$key: $value<br />"; } } } $student = new Student(); $student -> listStudentInfo();?> Roddy Link to comment Share on other sites More sharing options...
Synook Posted December 23, 2010 Share Posted December 23, 2010 Properties don't have the $ sign before them. foreach ($this->info as $key => $value) { echo "$key: $value<br />"; } Link to comment Share on other sites More sharing options...
iwato Posted December 23, 2010 Author Share Posted December 23, 2010 Properties don't have the $ sign before them.Yep, I knew there had to be an easy explanation.I am still a beginner.Thanks, Synook Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.