PHP多维数组提取和删除

时间:2017-06-25 14:41:40

标签: php arrays

使用PHP 5.3

我正在尝试从多维数组中提取并删除短语somestuffIdontwant

最好的方法是什么?

数组结构:

array(2) {
  [1]=>
  array(2) {
    ["date"]=>
"   string(148) "20170624 somestuffIdontwant 123425 086
    ["L-S_State"]=>
"   string(103) "state somestuffIdontwant entry1
  }
  [2]=>
  array(2) {
    ["date"]=>
"   string(148) "20170624 somestuffIdontwant 123425 086
    ["L-S_State"]=>
"   string(103) "state somestuffIdontwant entry2
  }
}

`

1 个答案:

答案 0 :(得分:1)

只需使用str_replaceereg_replace

即可

这样的事情:

foreach ($array as &$record) {
  foreach ($record as &$index) {
    $index = str_replace('somestuffIdontwant', '', $index);
  }
}