class User { // property public $name; // constructor public function __construct($name) { $this->name = $name; } // method public function sayHi() { echo "hi, i am $this->name!"; } } $tom = new User("Tom"); $bob = new User("Bob"); $red = new User("red"); $pink = new User("pink"); $you = new User("you"); $tim = new User("tim"); $names = array($tom,$bob,$red,$pink,$you,$tim); foreach($names as $name){ echo $name -> name(); }
phpの値を配列にして、foreachで取り出す方法が分かりません。
色々と試行錯誤しましたが、ずっとエラーになるので、質問させていただきました。
ご回答いただければ幸いです。
回答4件
あなたの回答
tips
プレビュー