douliexing2195 2010-05-11 00:31
浏览 36
已采纳

给定一个数组数组,如何从每个值中去掉子串“GB”?

Each item in my array is an array of about 5 values.. Some of them are numerical ending in "GB".. I need the same array but with "GB" stripped out so that just the number remains.

So I need to iterate through my whole array, on each subarray take each value and strip the string "GB" from it and create a new array from the output.

Can anyone recommend and efficient method of doing this?

  • 写回答

4条回答 默认 最新

  • douzhi3779 2010-05-11 00:39
    关注

    You can use array_walk_recursive() for this:

    array_walk_recursive($arr, 'strip_text', 'GB');
    
    function strip_text(&$value, $key, $string) {
      $value = str_replace($string, '', $value);
    }
    

    It's a lot less awkward than traversing an array with its values by reference (correctly).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?