I want to do var_export() and strip out all numerical array keys on an array. My array outputs like so:
array (
2 =>
array (
1 =>
array (
'infor' => 'Radiation therapy & chemo subhead',
'PPOWithNotif' => '',
'PPOWithOutNotif' => 'Radiation therapy & chemo PPO amount',
'NonPPO' => 'Radiation therapy & chemo Non PPO amount',
),
),
3 =>
array (
1 =>
array (
'infor' => 'Allergy testing & treatment subhead',
'PPOWithNotif' => '',
'PPOWithOutNotif' => 'Allergy testing & treatment PPO amount',
'NonPPO' => 'Allergy testing & treatment Non PPO amount',
),
)
)
By doing this I can shuffle the array values however needed without having to worry about numerical array values.
I’ve tried using echo preg_replace("/[0-9]+ \=\>/i", '', var_export($data)); but it doesn’t do anything. Any suggestions? Is there something I’m not doing with my regex? Is there a better solution for this altogether?
You have to set the second parameter of
var_exporttotrue, or else there is no return value given to yourpreg_replacecall.Reference: https://php.net/manual/function.var-export.php
Update: Looking back on this question, I have a hunch, a simple
array_values($input)would have been enough.