オブジェクトの配列の作成 1
$x = (object) [
'a' => 'test',
'b' => 'test2',
'c' => 'test3'
];
結果 :
object(stdClass)#1 (3) { ["a"]=> string(4) "test" ["b"]=> string(5) "test2" ["c"]=> string(5) "test3" }
オブジェクトの配列の作成 2
$object = new stdClass();
$object->property = 'Here we go';
結果 :
object(stdClass)#2 (1) { ["property"]=> string(10) "Here we go" }
オブジェクトの配列の作成 3
person オブジェクト作成
class Person
{
public $name;
public $age;
function birthday($age){
$age = $age + 1;
return $age;
}
}
$person1 = new Person();
$person1->name = 'David';
$person1->age = '23';
$person2 = new Person();
$person2->name = 'Nuno';
$person2->age = '21';
$person2->age = $person2->birthday($person2->age);
person オブジェクト配列追加
$person_array = array();
$person_array[] = $person1;
$person_array[] = $person2;