完善以下PHP代碼中的insertAt函數(shù),實(shí)現(xiàn)在數(shù)組$items的任意位置插入數(shù)據(jù)
陪伴而非守候
2019-04-19 16:10:52
TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊
@宋小北提到的array_splice是php原生實(shí)現(xiàn)。我們千萬(wàn)不要重復(fù)造輪子。這里造一個(gè),僅為了好玩。functioninsertAt($items,$value,$index=0){is_numeric($index)and$items[($index-'0.1').'x']=$valueandksort($items);returnarray_values($items);}
舉報(bào)