Convert stdClass object to array in PHP

0 votes

I fetched post_id from postmeta:

$post_id = $wpdb->get_results("SELECT post_id FROM $wpdb->postmeta WHERE (meta_key = 'mfn-post-link1' AND meta_value = '". $from ."')");

when I try to print_r($post_id); I have an array like this:

Array
(
    [0] => stdClass Object
        (
            [post_id] => 140
        )

    [1] => stdClass Object
        (
            [post_id] => 141
        )

    [2] => stdClass Object
        (
            [post_id] => 142
        )

)

I want to traverse it. Expected array:

Array
(
    [0]  => 140


    [1] => 141


    [2] => 142

)

How can I do this?

Jun 27, 2022 in PHP by narikkadan
• 63,420 points
2,258 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
0 answers

How to convert an array to object in PHP?

How can I convert an array like ...READ MORE

Jun 18, 2022 in PHP by narikkadan
• 63,420 points
322 views
0 votes
1 answer

How to convert a string to JSON object in PHP?

Hello @kartik, it seems that your JSON is ...READ MORE

answered Oct 20, 2020 in PHP by Niroj
• 82,880 points
5,042 views
0 votes
0 answers

How to convert an array to a string in PHP?

What can I do to get the ...READ MORE

May 30, 2022 in PHP by Kichu
• 19,050 points
415 views
0 votes
0 answers

How to convert a string to an array in php

I want to convert a string into ...READ MORE

Jun 1, 2022 in PHP by Kichu
• 19,050 points
249 views
0 votes
1 answer

How do I convert a PDF document to a preview image in PHP?

Hello @kartik, You need ImageMagick and GhostScript <?php $im = new imagick('file.pdf[0]'); $im->setImageFormat('jpg'); header('Content-Type: image/jpeg'); echo ...READ MORE

answered Aug 14, 2020 in PHP by Niroj
• 82,880 points
4,300 views
–1 vote
1 answer
0 votes
1 answer

How to check if array is multidimensional or not?

Since the 'second dimension' could be just ...READ MORE

answered Nov 5, 2018 in Others by DataKing99
• 8,240 points
5,290 views
0 votes
1 answer

How to store input value into array then localstorage?

Hello @ abhittac, You have create the array everytime the ...READ MORE

answered Jul 24, 2020 in Java-Script by Niroj
• 82,880 points
8,690 views
0 votes
1 answer

Convert a PHP object to an associative array

Start with simply typecasting the line:- $array = ...READ MORE

answered Feb 23, 2022 in PHP by Aditya
• 7,680 points
1,694 views
0 votes
0 answers

php var_dump() vs print_r()

What is the difference between var_dump() and print_r() in terms of ...READ MORE

May 28, 2022 in PHP by Kichu
• 19,050 points
372 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP