When querying the database using wpdb class in WordPress I often get a numerical array of objects:
array(
[0] => stdClass(
comment_ID = 3
comment_post_ID = 19
user_id = 7
)
[1] => stdClass(
comment_ID = 5
comment_post_ID = 19
user_id = 6
)
)
I require to perform a second query using the user_id. To retrieve the user_id I use a foreach loop like:
$user_ids = array();
foreach($array as $object) {
$user_ids[] = $object->user_id;
}
I want to know whether there is a PHP native better way of retrieving the user_id and avoid the foreach altogether?
whileloop? Without seeing how you're using the DB class, it's difficult to provide an accurate answer really.INNER JOINto form query that would return list with required data so you wouldn't need to send multiple queries to the database which will be faster as well as less loops are needed.