How to remove spaces in array keys names in php?

前端 未结 3 2035
你的背包
你的背包 2020-12-20 02:08

I am trying to remove all spaces in array keys names i.e. str_replace(\' \',\'\',$value) (or worst cast scenario replace them with underscores (_) )

and I am trying

3条回答
  •  天命终不由人
    2020-12-20 02:34

    function array_stripstuff(&$elem)
    {
      if (is_array($elem)) {
        foreach ($elem as $key=>$value)
          $elem[str_replace(" ","-",$key)]=$value;
      }
      return $elem;
    }
    
    $strippedarray = array_walk_recursive($yourarray,'array_stripstuff');
    

    There you go :-)

提交回复
热议问题