As from the database at once to a simple array?

Send a request to the DB and get this array:
$order_ids_approved = $wpdb->get_results( "SELECT `ID` FROM `avt_posts` WHERE `post_status` = 'wc-approved' AND (`post_date` BETWEEN '{$start_day}' AND '{$end_day}')" );

array(3) { [0]=> object(stdClass)#23446 (1) { ["ID"]=> string(5) "12160" } [1]=> object(stdClass)#23412 (1) { ["ID"]=> string(5) "12162" } [2]=> object(stdClass)#23444 (1) { ["ID"]=> string(5) "12163" } }

How to get from database array like this?
array(3) { [0]=> string(5) "12160" [1]=> string(5) "12162" [2]=> string(5) "12163" }

Now by means of the "foreach" to get the desired array for further work, but I think it is not correct.
$order_ids_approved = $wpdb->get_results( "SELECT `ID` FROM `avt_posts` WHERE `post_status` = 'wc-approved' AND (`post_date` BETWEEN '{$start_day}' AND '{$end_day}')" );

$order_id_name = [];
foreach ( $order_ids_approved as $order_id_approved ) :
 $order_id_name[] = $order_id_approved->ID;
endforeach;
June 8th 19 at 17:01
2 answers
June 8th 19 at 17:03
Solution
rechecked themselves
parameter OBJECT_K
$order_ids_approved = $wpdb->get_results( "SELECT `ID` FROM `avt_posts` WHERE `post_status` = 'wc-approved' AND (`post_date` BETWEEN '{$start_day}' AND '{$end_day}')", OBJECT_K);


will be given an associative array, "first", the keys of which will be the first value in the SQL query, in this case "ID". i.e. if you need the same ID, it will be possible to take them with either brute force foreach
foreach($rows as $key => $row)
where $key will be our desired value
or to perform the function array_keys
and get a new array with the keys (ajtishnikam)
June 8th 19 at 17:05
https://developer.wordpress.org/reference/classes/...
$order_ids_approved = $wpdb->get_results( "SELECT `ID` FROM `avt_posts` WHERE `post_status` = 'wc-approved' AND (`post_date` BETWEEN '{$start_day}' AND '{$end_day}')", ARRAY_A );
Then we get an associative array - Roy_Dicki commented on June 8th 19 at 17:08
and if OBJECT_K? )) - nikolas.Reichert commented on June 8th 19 at 17:11
judging by the code, then OBJECT_K - needs to be associative (not nested) array, which can go a normal foreach - nikolas.Reichert commented on June 8th 19 at 17:14
Yes, that's right! Thank you! I'm just stupid) - Roy_Dicki commented on June 8th 19 at 17:17

Find more questions by tags MySQLWordPress