1

I'm using the following to show my Array contents:

var_dump($categories);

Contents:

array(1) {
  [0]=>
  object(stdClass)#114 (16) {
    ["term_id"]=> &string(1)  "3"
    ["name"]=>    &string(10) "Recordings"
    ["slug"]=>    &string(9)  "recording"
  }
}

My Question is, how do I retrieve the slug value?

I had tried $categories[0]["slug"] but with no success.

Many thanks for any guidance.

1
  • @brian: comment != answer....... Commented Mar 4, 2011 at 15:49

4 Answers 4

4

You can get the slug by using:

$categories[0]->slug;

Because the first element in your array is an object e.g stdClass you have too acces its values like an object.

Sign up to request clarification or add additional context in comments.

Comments

2

you would do:

$categories[0]->slug

More than likley this has come from PDO or something, so you may have multiple categories, (hence the name)

you should loop them to get each category like so:

foreach($categores as $category)
{
    echo $category->slug . "\n";
}

Comments

1
var_dump($categories[0]->slug);

Comments

1
echo $categories[0]->slug;

this is object and you have to use something above.

1 Comment

Thank you Shakti for taking the time to help out. It's perfect.

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.