Mr. B
Mr. B

Reputation: 2787

echo specific part of array in php

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

Answers (2)

B. Desai
B. Desai

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

justyand
justyand

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

Related Questions