I've been trying to push an item to an associative array like this:
$new_input['name'] = array(
'type' => 'text',
'label' => 'First name',
'show' => true,
'required' => true
);
array_push($options['inputs'], $new_input);
However, instead of 'name' as the key in adds a number. Is there another way to do it?
You can use array_merge($array1, $array2) to merge the associative array. Example:
Output:
If
$new_input
may contain more than just a 'name' element you may want to usearray_merge
.Just change few snippet(use array_merge function):-
i use
php5.6
code:
output
Curtis's answer was very close to what I needed, but I changed it up a little.
Where he used:
I used:
Here's my actual code using a query from a DB:
Thanks!