PHP array_push()创建一个关联数组
要在PHP中创建关联数组,请使用[]方括号。
示例
输出结果<!DOCTYPE html>
<html>
<body>
<?php
$emp= (object) [
'employeeId'=>"101",
'employeeFirstName'=>"John",
'employeeLastName'=>"Doe",
'employeeCountryName'=>"AUS"
];
$employeeDetails[] = [
'emp_id' => $emp->employeeId,
'emp_first_name' => $emp->employeeFirstName,
'emp_last_name' => $emp->employeeLastName,
'emp_country_name' => $emp->employeeCountryName
];
print_r(array_values($employeeDetails));
?>
</body>
</html>
Array ( [0] => Array ( [emp_id] => 101 [emp_first_name] => John [emp_last_name] => Doe [emp_country_name] => AUS ) )