I need to remove some character from string search by value using PHP. I am explaining my code below.
Current Data
$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"
)
);
Expected Output
$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"
)
);
From the above array there is a date field value and I need to remove the AM/PM from all date using PHP.
Use rtrim to remove the tailing chars like this,
$datArr = array_map(function($v){
$v['date'] = rtrim($v['date'], " APMapm");
return $v;
}, $datArr);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With