Answers for "how to add element at the start of the array in php"

PHP
5

php add element to array first position

<?php
$queue = array("orange", "banana");
array_unshift($queue, "apple", "raspberry");
print_r($queue);
?>
  Array
(
    [0] => apple
    [1] => raspberry
    [2] => orange
    [3] => banana
)
Posted by: Guest on August-13-2020
0

array prepend php

$arr = array('item2', 'item3', 'item4');
array_unshift($arr , 'item1');
print_r($arr);
Posted by: Guest on November-04-2021

Code answers related to "how to add element at the start of the array in php"

Browse Popular Code Answers by Language