Answers for "add element in first arrary php with key"

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
8

push key value array php

$a = array("key1"=>"value1", "key2"=>"value2");

// to append "key3" - "value3":
$a["key3"] = "value3"
Posted by: Guest on August-23-2021

Code answers related to "add element in first arrary php with key"

Browse Popular Code Answers by Language