从var_export中删除数值数组键

Web*_*net 7 php arrays

我想做var_export()去掉数组上的所有数值数组键.我的数组输出如下:

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',
    ),
  )
)
Run Code Online (Sandbox Code Playgroud)

通过这样做,我可以随机播放数组值而无需担心数值数组值.

我尝试过使用echo preg_replace("/[0-9]+ \=\>/i", '', var_export($data));但它没有做任何事情.有什么建议?我的正则表达式有什么我没做的吗?有没有更好的解决方案呢?

Yos*_*shi 3

您必须设置var_exportto的第二个参数true,否则您的调用不会有返回值preg_replace


参考: https: //php.net/manual/function.var-export.php

return
如果使用并设置为TRUEvar_export()将返回变量表示形式而不是输出它。


更新:回顾这个问题,我有一种预感,一个简单的array_values($input)就足够了。

  • 例如: <?php $export = preg_replace('(\d+\s=>)', "", var_export($arr, true)); (6认同)