array push for associative array in php code example
Example 1: php add to associative array
$data += [$key => $value];
$data += array($key => $value);
Example 2: array_push php
<?php
$cesta = array("laranja", "morango");
array_push($cesta, "melancia", "batata");
print_r($cesta);
?>
Example 3: array_push in php
<?php
$a=array("red","green");
array_push($a,"blue","yellow");
print_r($a);
?>
Example 4: php add to existing associative array
$a1=['aa'=>'123' , 'bb'=>'454'];
$a1 = array_merge( $a1 , ['a'=>1,'b'=>2] ) ;
Example 5: php add new item to associative array
$a = array('foo' => 'bar');
$a['Title'] = 'blah';