php add element to middle of associative array code example
Example 1: php add to associative array
// for php 5.4+
$data += [$key => $value];
// for php 5.4-
$data += array($key => $value);
Example 2: php add element to beginning of associative array
$arr1 = array('key0' => 'value0') + $arr1;
-------------- OR ------------------
<?php
$arr = array('key1' => 'value1', 'key2' => 'value2');
$arr = array_merge(array('key0' => 'value0'), $arr);