"Ram", -6ren">
gpt4 book ai didi

php - 如何使用PHP从字符串中删除一些字符

转载 作者:可可西里 更新时间:2023-11-01 01:13:09 27 4
gpt4 key购买 nike

我需要使用 PHP 按值从字符串搜索中删除一些字符。我在下面解释我的代码。

当前数据

$datArr = array(
array(
"name" => "Ram",
"id" => 1,
"date" => "12/04/2017 05:31:57 AM"
),
array(
"name" => "Rahim",
"id" => 5,
"date" => "12/03/2017 12:31:57 PM"
),
array(
"name" => "Raj",
"id" => 4,
"date" => "12/04/2017 05:31:57 PM"
)
);

预期输出

$datArr = array(
array(
"name" => "Ram",
"id" => 1,
"date" => "12/04/2017 05:31:57"
),
array(
"name" => "Rahim",
"id" => 5,
"date" => "12/03/2017 12:31:57"
),
array(
"name" => "Raj",
"id" => 4,
"date" => "12/04/2017 05:31:57"
)
);

从上面的数组中有一个 date 字段值,我需要使用 PHP 从所有日期中删除 AM/PM

最佳答案

像这样使用 rtrim 删除尾字符,

$datArr = array_map(function($v){
$v['date'] = rtrim($v['date'], " APMapm");
return $v;
}, $datArr);

关于php - 如何使用PHP从字符串中删除一些字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47646557/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com