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_export
to true
, or else there is no return value given to your preg_replace
call.
Reference: https://php.net/manual/function.var-export.php
return
If used and set to TRUE, var_export() will return the variable representation instead of outputting it.
Update: Looking back on this question, I have a hunch, a simple array_values($input)
would have been enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With