5

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?

1
  • Have provided with a solution for the request that you have asked the question. Have a try and share thoughts. Commented Oct 7, 2016 at 5:30

4 Answers 4

8

Try this:

echo $array[0]->id;
echo $array[0]->book_category;
Sign up to request clarification or add additional context in comments.

1 Comment

how do you get the output above (the one in your question)?
4

This will get the value easily out

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

1 Comment

Sorry i didn't see the "without" have you tried for ($x=0;$x<count($array);$x++){ echo $array[$x]->id;}
1

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

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.