如何删除数组中的特定单词?
例如:
$results = array (
'date' => '22. jan.',
'flightNumber' => 'EZY6747',
'airline' => 'easyJet',
'from' => 'Belfast International',
'plannedArrival' => '18:35',
'realArrival' => 'Estimated Arrival 18:32'
);
从"Arrival"
中删除单词'realArrival'
以输出:
$results = array (
'date' => '22. jan.',
'flightNumber' => 'EZY6747',
'airline' => 'easyJet',
'from' => 'Belfast International',
'plannedArrival' => '18:35',
'realArrival' => 'Estimated 18:32'
);
我希望你明白我在说什么。
答案 0 :(得分:0)
假设你想要对每个值进行某些操作(删除Arrival),你可以使用它:
<?php
$results = array (
'date' => '22. jan.',
'flightNumber' => 'EZY6747',
'airline' => 'easyJet',
'from' => 'Belfast International',
'plannedArrival' => '18:35',
'realArrival' => 'Estimated Arrival 18:32'
);
$result2 = array_map(function($s)
{
return str_replace('Arrival ', '', $s);
}, $results);
print_r($result2);