1<?php
2$a=array("a"=>"red","b"=>"green");
3array_push($a,"blue","yellow");
4print_r($a);
5?>
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
1// laravel
2
3use Illuminate\Support\Arr;
4
5$array = Arr::add(['name' => 'Desk'], 'price', 100);
6
7// or this one:
8
9
10$array = Arr::add($array, 'price', 100);
11
12
13