1$a = array("key1"=>"value1", "key2"=>"value2");
2
3// to append "key3" - "value3":
4$a["key3"] = "value3"
1<?php
2$a=array("a"=>"red","b"=>"green");
3array_push($a,"blue","yellow");
4print_r($a);
5?>
1// If you are creating new array then try this :
2$arr = array("key" => "value");
3
4// And if array is already created then try this :
5$arr["key"] = "value";
1// Error : "array_push() expects parameter 1 to be array, null given"
2// Don't array_push($array,$arrayValueToPush);
3// Set the array value.
4$array["arrayKey"] = $arrayValue;
5//----------------------------------------
6$newArray = [];
7foreach ($arrayItems as $key => $arrayItem) {
8 $newArray[$key]["arrayItemKey1"] = $arrayItem["arrayItemKey1FromArrayItem"];
9 $newArray[$key]["arrayItemKey2"] = $arrayItem["arrayItemKey2FromArrayItem"];
10}
1use Illuminate\Support\Arr;
2
3$array = Arr::add(['name' => 'Desk'], 'price', 100);
4
5// or this one:
6
7
8$array = Arr::add($array, 'price', 100);
9
10
11