Answer the question
In order to leave comments, you need to log in
How to immediately get a simple array from the database?
I send a query to the database and get the following 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" } }
array(3) { [0]=> string(5) "12160" [1]=> string(5) "12162" [2]=> string(5) "12163" }
$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;
Answer the question
In order to leave comments, you need to log in
rechecked with the OBJECT_K
parameter
an associative array will be given, the "first" keys of which will be the first value in the SQL query, in this case "ID". those. just if the same IDs are needed, then it will be possible to take them either with a foreach enumeration
where $key will be our desired value,
or execute the array_keys function
and get a new array with keys (IDs)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question