Answers for "push in from of array php inserts one or more elements to the start of an array"

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
0

php add element to beginning of associative array

$arr1 = array('key0' => 'value0') + $arr1;

-------------- OR ------------------

<?php
$arr = array('key1' => 'value1', 'key2' => 'value2');
$arr = array_merge(array('key0' => 'value0'), $arr);
Posted by: Guest on October-17-2020

Code answers related to "push in from of array php inserts one or more elements to the start of an array"

Browse Popular Code Answers by Language