在PHP中,可以通过以下方式定义对象数组:
$obj1 = new stdClass();
$obj1->name = "John";
$obj1->age = 25;
$obj2 = new stdClass();
$obj2->name = "Jane";
$obj2->age = 30;
$arr = array($obj1, $obj2);
$obj1 = new stdClass();
$obj1->name = "John";
$obj1->age = 25;
$obj2 = new stdClass();
$obj2->name = "Jane";
$obj2->age = 30;
$arr = [$obj1, $obj2];
$obj1 = new stdClass();
$obj1->name = "John";
$obj1->age = 25;
$obj2 = new stdClass();
$obj2->name = "Jane";
$obj2->age = 30;
$arr = [$obj1, $obj2];
这样就定义了一个包含对象的数组。你可以通过索引访问数组中的对象,并使用箭头运算符(->)访问对象的属性。