Padam Shankhadev
Padam Shankhadev

Reputation: 71

how to get value from array with stdclass object?

I have get following output in codeigniter?

Array
(
    [0] => stdClass Object
        (
            [id] => 8
            [book_category] => C Program
            [book_id] => 2
            [book_name] => C Language
            [book_category_id] => 8
            [book_in_stock] => 5
        )

    [1] => stdClass Object
        (
            [id] => 8
            [book_category] => C Program
            [book_id] => 1
            [book_name] => C++
            [book_category_id] => 8
            [book_in_stock] => 10
        )

    [2] => stdClass Object
        (
            [id] => 9
            [book_category] => English
            [book_id] => 3
            [book_name] => Comp Eng
            [book_category_id] => 9
            [book_in_stock] => 5
        )

    [3] => stdClass Object
        (
            [id] => 9
            [book_category] => English
            [book_id] => 4
            [book_name] => Eng English
            [book_category_id] => 9
            [book_in_stock] => 5
        )

)

so i need get value from the above array without foreach of debugging purpose?

Upvotes: 5

Views: 24056

Answers (4)

Aliya
Aliya

Reputation: 11

Arrays are never get echoed,Try this with print_r();

Upvotes: 1

young pac
young pac

Reputation: 73

This will get the value easily out

foreach($array as $key =>$value){ 
  echo $array[$key]->id;
  echo $array[$key]->book_category;
}

Upvotes: 4

jolivier
jolivier

Reputation: 7635

var_dump is the way to go if you wan to see the content of your array easily.

Upvotes: 1

ariefbayu
ariefbayu

Reputation: 21979

Try this:

echo $array[0]->id;
echo $array[0]->book_category;

Upvotes: 8

Related Questions