Reputation: 2787
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'];
?>
Upvotes: 1
Views: 4175
Reputation: 16436
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
Upvotes: 1
Reputation: 31
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
Upvotes: 0