這篇文章主要介紹了php中array_unshift()修改數組key注意事項,實例分析了array_unshift()函數在處理鍵值為數字類型時自動轉換鍵值的情況,需要的朋友可以參考下
眾所周知,array_unshift()用來在數組的開頭添加元素,但今天突然發現如果數組的鍵值是數字類型的(或能轉成數字類型的),array_unshift()會修改所有鍵為數字的元素的Key,真是坑啊
實例:
#$a=array(111=>"dddddddddddd","112"=>array("one"=>"orange","two"=>"hhhhh"), "113"=>array("one"=>"orange","two"=>"hhhhh"),"oooo"=>"jjjjj"); print_r($a);echo "</br>"; array_unshift($a, "aaaaaaaaa"); print_r($a);echo "</br>";
Array ( [111] => dddddddddddd [112] => Array ( [one] => orange [two] => hhhhh ) [113] => Array ( [one] => orange [two] => hhhhh ) [oooo] => jjjjj ) Array ( [0] => aaaaaaaaa [1] => dddddddddddd [2] => Array ( [one] => orange [two] => hhhhh ) [3] => Array ( [one] => orange [two] => hhhhh ) [oooo] => jjjjj )
以上是php中array_unshift()修改陣列key注意事項及實例分析的詳細內容。更多資訊請關注PHP中文網其他相關文章!