我试图在explode
上执行array
,以从称为'
的特定字段中删除撇号minute
,该数组具有以下结构:
[
{
"id": "15888",
"round_id": "488",
"home_team_id": "95",
"away_team_id": "104",
"team_id": "95",
"player_marker_id": "68165",
"player_assist_id": "319468",
"match_id": "2564737",
"minute": "8'",
"result": "1 - 0",
"type": "1"
},
下面是我的代码:
$goals = $sql->fetchAll(); //Take data from table
//replace the field removing the '
$goals = array_map(function($x) use($a)
{
return [$a[0], $x];
}, explode("'", $a[1]["minute"]));
return $goals;
我得到:
[
[
null,
""
]
]
我做错了什么?
答案 0 :(得分:0)
希望这对您有帮助:(删除'
的替代方法)
$json ='[{"id": "15888","round_id": "488","home_team_id": "95","away_team_id": "104","team_id": "95","player_marker_id": "68165","player_assist_id": "319468","match_id": "2564737","minute": "8\'","result": "1 - 0","type": "1"}]';
$goals = json_decode($json);
foreach ($goals as $key => $item)
{
$item->minute = rtrim($item->minute,"'");
$data[$key] = $item;
}
print_r($data);
输出:
Array
(
[0] => stdClass Object
(
[id] => 15888
[round_id] => 488
[home_team_id] => 95
[away_team_id] => 104
[team_id] => 95
[player_marker_id] => 68165
[player_assist_id] => 319468
[match_id] => 2564737
[minute] => 8
[result] => 1 - 0
[type] => 1
)
)