Answers for "add element to array with key php"

PHP
0

php array push with key

<?php
$a=array("a"=>"red","b"=>"green");
array_push($a,"blue","yellow");
print_r($a);
?>
Posted by: Guest on March-08-2021
1

insert key-value pair into array php

// If you are creating new array then try this :
$arr = array("key" => "value");

// And if array is already created then try this :
$arr["key"] = "value";
Posted by: Guest on April-28-2020
2

php array push with key

// Error : "array_push() expects parameter 1 to be array, null given"
// Don't array_push($array,$arrayValueToPush); 
// Set the array value.
$array["arrayKey"] = $arrayValue;
//----------------------------------------
$newArray = [];
foreach ($arrayItems as $key => $arrayItem) {
  $newArray[$key]["arrayItemKey1"] = $arrayItem["arrayItemKey1FromArrayItem"];
  $newArray[$key]["arrayItemKey2"] = $arrayItem["arrayItemKey2FromArrayItem"];
}
Posted by: Guest on February-17-2021
0

add key value array php

// laravel

use Illuminate\Support\Arr;

$array = Arr::add(['name' => 'Desk'], 'price', 100);

// or this one:
  
  
$array = Arr::add($array, 'price', 100);
Posted by: Guest on July-12-2021
0

php array push key value

<?php
$image[0] = $image[0].','.$filename;
?>
Posted by: Guest on October-21-2020

Code answers related to "add element to array with key php"

Browse Popular Code Answers by Language