"how to insert an item at the beginning of an array in php?" Code Answer

4

Use array_unshift($array, $item);

$arr = array('item2', 'item3', 'item4');
array_unshift($arr , 'item1');
print_r($arr);

will give you

Array
(
 [0] => item1
 [1] => item2
 [2] => item3
 [3] => item4
)
By mada_zaharia-11e20e938c37 on September 26 2022

Answers related to “how to insert an item at the beginning of an array in php?”

Only authorized users can answer the search term. Please sign in first, or register a free account.