I have an object called $definition in PHP.
When I
print_r($definition);
I get
Array ( [0] => Definition Object ( [extendedText] => [text] => Any of several carnivorous burrowing mammals of the family Mustelidae, such as Meles meles of Eurasia or Taxidea taxus of North America, having short legs, long claws on the front feet, and a heavy grizzled coat. [source] => [sourceDictionary] => ahd-legacy [citations] => Array ( ) [labels] => Array ( ) [score] => 0 [exampleUses] => Array ( ) [attributionUrl] => [seqString] => [attributionText] => from The American Heritage® Dictionary of the English Language, 4th Edition [relatedWords] => Array ( ) [sequence] => 0 [word] => badger [textProns] => Array ( ) [notes] => Array ( ) [partOfSpeech] => noun ) )
How do I print out the “text” and “partOfSpeech” components?
I’ve tried $definition->text, $definition[0][‘text’], $definition[‘text’]….
I’m lost…
Try:
echo $definition[0]->text;and
echo $definition[0]->partOfSpeech;its created the object as the first index of the array 🙂
Edit:
With PHP, you can actually store multiple objects in an array. Which is cool, because instead of passing a ton of, for arguments sake, articles to a view, you can do something awesome like:
So in this example (and in yours) instead of setting the variable articles to an object, we have set the index of the array to an object.
So if we wanted to pull out the 3rd article, we would do:
So with your vardump, we can see that its associated an index of 0 to that object.
Annoying on why it did that.
You could do this however to drop it: