0

If i print an array $cat i get

Array ( [1] => stdClass Object ( [cat_id] => 1 ..
Array ( [2] => stdClass Object ( [cat_id] => 2 ..

but if I try to get the cat_id

var_dump($cat->cat_id);

How can i do that?

1
  • 2
    You need an offset for your $cat array: var_dump($cat[0]->cat_id); Commented Sep 4, 2012 at 13:47

6 Answers 6

3
foreach($cat AS $singleCat){
   echo $singleCat->cat_id;
}
Sign up to request clarification or add additional context in comments.

Comments

2

$cat is an Array.

So,

var_dump($cat[1]->cat_id);

Comments

1

try var_dump($cat[0]->cat_id);

Comments

1

$cat is an array. You need to access the index which contains an object before you can access that object's properties:

var_dump($cat[1]->cat_id);

Comments

1

If you want to get all of the cat_ids...

foreach ($cat as $row) {
  echo $row->cat_id;
}

Comments

1

As $cat is an array, you need to use index

var_dump($cat[1]->cat_id);//This will work

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.