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?
Instead of array_push(), use array_merge()
It will merge two arrays and combine their items in a single array.
Example Code -
Its returns the resulting array in the final_array. And results of resulting array will be -
Please review this link, to be aware of possible problems.
You can try.
First of all, you need to define an array
Then you can push anything to your array, here I try with an associative array
You can see the changed array in php:
WebbieDave's solution will work. If you don't want to overwrite anything that might already be at 'name', you can also do something like this:
$options['inputs']['name'][] = $new_input['name'];
This is a cool function
Just use
Credits & Explanation