PHP array change value
one text
I'm stuck at a small problem, I tried some things but it didn't work. I have a reservation system (in Wordpress) that generates a database with all info. Everything works fine except the sorting of the reservations on date. It sorts on day and month but ignores the year. The reason: format of the date is a string = Month/Day/Year (ex. 05/20/2021). This can't be changed in the database!
The solution would be to change all values in the array to a real date or just a numeric value like YYYYMMDD (ex. 20210520). But for some reason I can't get it right. Can you help me?
This is my array:
$args = array(
'post_type' => 'homey_reservation',
'meta_key' => 'reservation_checkin_date',
'orderby' => 'meta_value',
'order' => 'ASC',
'paged' => $paged,
'posts_per_page' => $listing_no,
);
foreach ($args as $meta_key => $field) {
$split = explode("/",$meta_key);
$day = $split[1];
$month = $split[0];
$year = $split[2];
$field = $year.$month.$day;
}
Source