This question already has an answer here:
I have a php code.
$metadata = Array(
'facebook' => Array(
'title' => 'og:title',
'type' => 'og:type',
'url' => 'og:url',
'thumbnail' => 'og:image',
'sitename' => 'og:site_name',
'key' => 'fb:admins',
'description' => 'og:description'
),
'google+' => Array(
'thumbnail' => 'image',
'title' => 'name',
'description' => 'description'
),
'twitter' => Array(
'card' => 'twitter:card',
'url' => 'twitter:url',
'title' => 'twitter:title',
'description' => 'twitter:description',
'thumbnail' => 'twitter:image'
)
);
what does the => means. How to access an element in this array.
</div>
You have a multi dimensional array, so facebook, google and twitter are elements of the 1st dimension of the $metadata array and they are arrays themselves, here lies the multi dimension.
The => is just like an arrow pointing to the value/data.
To access the 1st dimension would be $metadata['twitter']; or $metadata[2]; it's the same statement, this would bring back the elements/keys of the twitter array.
To access the 2nd dimension would be $metadata['twitter']['card']; or $metadata[2][0]; again the two statements are the same, this would bring back the value of the element/key card
what does the => means.
As documented under Arrays:
An array in PHP is actually an ordered map. A map is a type that associates values to keys.
[ deletia ]An array can be created using the array() language construct. It takes any number of comma-separated key => value pairs as arguments.
array( key => value, key2 => value2, key3 => value3, ... )
How to access an element in this array.
As documented under Accessing array elements with square bracket syntax:
Array elements can be accessed using the array[key] syntax.
Example #6 Accessing array elements
<?php $array = array( "foo" => "bar", 42 => 24, "multi" => array( "dimensional" => array( "array" => "foo" ) ) ); var_dump($array["foo"]); var_dump($array[42]); var_dump($array["multi"]["dimensional"]["array"]); ?>
The above example will output:
string(3) "bar" int(24) string(3) "foo"