1

I'm still learning php arrays and I'm trying to echo a

array(8) { [0]=> string(9) "site_name" [1]=> string(3) "url" [2]=> string(5) "title" [3]=> string(11) "description" [4]=> string(4) "type" [5]=> string(5) "image" [6]=> string(11) "image:width" [7]=> string(12) "image:height" } NULL site_name => Playbuzzurl => http://www.playbuzz.com/jordonr10/what-modern-societal-archetype-fits-your-personalitytitle => What Modern Societal Archetype Fits Your Personality?description => It's 2017, so it's about time we update the books!type => articleimage => http://cdn.playbuzz.com/cdn/aef166e1-1574-4d57-9823-3f38f30bcfc4/810f1d3e-0a97-4797-8235-b4c988562a1c.jpgimage:width => 1600image:height => 842

array(8) { [0]=> string(9) "site_name" [1]=> string(3) "url" [2]=> string(5) "title" [3]=> string(11) "description" [4]=> string(4) "type" [5]=> string(5) "image" [6]=> string(11) "image:width" [7]=> string(12) "image:height" } NULL site_name => Playbuzzurl => http://www.playbuzz.com/jordonr10/what-modern-societal-archetype-fits-your-personalitytitle => What Modern Societal Archetype Fits Your Personality?description => It's 2017, so it's about time we update the books!type => articleimage => http://cdn.playbuzz.com/cdn/aef166e1-1574-4d57-9823-3f38f30bcfc4/810f1d3e-0a97-4797-8235-b4c988562a1c.jpgimage:width => 1600image:height => 842

I'm trying to echo just the value for description which is It's 2017, so it's about time we update the books!

I've tried several different things, but nothing works. Any help is greatly appreciated.

echo $array[0]['description'];      // returns nothing
var_dump($key);                     // returns string(12) "image:height"

Current Code

<?php
require_once('OpenGraph.php');

$graph = OpenGraph::fetch('http://www.playbuzz.com/jordonr10/what-modern-societal-archetype-fits-your-personality');
var_dump($graph->keys());
var_dump($graph->schema);

foreach ($graph as $key => $value) {
    echo "$key => $value<br><hr>";
}
echo "Value Below<hr>";
echo $array['description'];

?>
2
  • the value of the description is outside of your array. You need to put it in an array first before you are able to get it. Commented Jun 7, 2017 at 5:16
  • 1
    show the code you used here. Commented Jun 7, 2017 at 5:17

2 Answers 2

1

From your code its seems that you can directly get value of description from $graph if key is already there. Also you are trying to diplay $array['description']; here I can see $array is define any where

try to

 echo $graph['description']; // if $graph is array

OR

echo $graph->description; // If its an object
Sign up to request clarification or add additional context in comments.

2 Comments

It is an Object. That explains why everything I was trying was failing. How do you tell the difference between object and array in the above? Thanks again!
Use var_dump($graph); The result will show you whether it is object or an array
0

Just call

echo $array[3];

Or use associative arrays which can be called

echo $array['description'];

http://php.net/manual/en/language.types.array.php

4 Comments

Hey justyand, Thanks for offering assistance. I did try both of those too, but neither work. Any other ideas?
No problem. First place your code. Then we can talk about malfunctioning. Basicaly first define an array, then call echo
@Mr.B your question doesn't make sense, read first comment under your question.
So from code it's obvious that $array is not defined You have to use $graph

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.