Skip to content
Advertisement

how to remove part of values from array in php

I have an array with date & time like below:

$array = array('2021-05-04T10:00', '2021-05-05T10:00', '2021-05-06T10:00');

From each value, the T10:00 should be cut off, so that my new array looks like this:

$new_array = array('2021-05-04', '2021-05-05', '2021-05-06');

How can i do that?

Advertisement

Answer

$array = array('2021-05-04T10:00', '2021-05-05T10:00', '2021-05-06T10:00');
$new_array = [];
foreach($array as $a) {
  $a = explode('T', $a)[0];
  array_push($new_array, $a);
}
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement