what is the meaning of => while using arrays in php
This question already has an answer here:
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"
上一篇: 将foreach语句转换为for
下一篇: 在php中使用数组时,=>的含义是什么