php add to associative array code example
Example 1: php add to associative array
$data += [$key => $value];
$data += array($key => $value);
Example 2: Associative array in php
<?php
$age = array("Samy"=>"35", "Naveen"=>"37", "Amit"=>"43");
echo "Mr.Samy is " . $age['Samy'] . " years old.";
?>
Example 3: php add to existing associative array
$a1=['aa'=>'123' , 'bb'=>'454'];
$a1 = array_merge( $a1 , ['a'=>1,'b'=>2] ) ;
Example 4: php add new item to associative array
$a = array('foo' => 'bar');
$a['Title'] = 'blah';