1
我試圖將數組插入到其他數組中,問題是當我調用array_push()方法覆蓋數組的最後一個元素時,我只是得到一個數組一個數組(最後一個)的數據:PHP將數組插入到多維數組中被覆蓋
$users_data = [];
$resultSize = count($result);
$data = $result;
for ($i = 0; $i < $resultSize; $i++) {
$person = [
'nombre' => $result[$i]['nombre'],
'apellido' => $result[$i]['apellido'],
];
array_push($users_data, $person);
// $users_data = $person; I also have tried with this method.
};
我剛剛收到一個對象與此:
Object {nombre: jane, apellido: doe}
到底哪裏出問題了?
謝謝!它工作完美! –
@LeonardoCavani考慮接受答案,如果它有幫助。 –
我需要8分鐘做XD。謝謝 ! –