How to clone an array of objects in PHP?

后端 未结 15 739
鱼传尺愫
鱼传尺愫 2020-12-13 17:00

I have an array of objects. I know that objects get assigned by \"reference\" and arrays by \"value\". But when I assign the array, each element of the array is referencing

15条回答
  •  情书的邮戳
    2020-12-13 17:27

    or also

    $nuarr = json_decode(json_encode($array));
    

    but it is expensive, I prefer Sebastien version (array_map)

提交回复
热议问题