I have array element stored in $sal to put at the start of an array $fields[‘billing’]. i am using array_unshift for this purpose.
$sal = array(
'label' => __('Tratamiento', 'woocommerce'),
'placeholder' => _x('', 'placeholder', ''),
'required' => 0,
'clear' => true,
'class' => array('form-row form-row-wide'),
'type' => 'select',
'options' => array(
'Señor' => __('Señor', 'woocommerce' ),
'Señora' => __('Señora', 'woocommerce' ),
'Señorita'=> __('Señorita', 'woocommerce')
)
);
array_unshift($fields['billing'] , $sal);
array_unshift adding element at the start of array at 0 key index. after print_r i see:
[0] => Array
(
[Label] => Treatment
[Placeholder] =>
[Required] => 0
[Clear] => 1
[Class] => Array
(
[0] => form-row-row-wide form
)
[Type] => select
[Options] => Array
(
[Lord] => Lord
[Lady] => Lady
[Ms.] => Miss
)
)
My problem is only that i just want to change the key value from [0] to [‘saluation’], i can simply do that with:
$fields['billing']['saluation'] = $fields['billing'][0];
unset($fields['billing'][0]);
but i also want it at the start of array. i tried many techniques but still unable to figure this out.
this is actully woocommerce fields arrays which i am dealing with.
I just solved it by array_merge() function.