$arrayVariable = array (key1 = > value1, key2 = > value2, key3 = > value3, .. . keyN = > valueN,);Syntax 2:Using shorthand
$arrayVariable = [key1 = > value1, key2 = > value2, key3 = > value3, ... keyN = > valueN,];Notes :
$websites
=
array
(
"Facebook"
= >
" Facebook, Inc. is an online social media
and
social networking service company.",
"Twitter"
= >
"Twitter is a microblogging
and
social networking service on
which users post
and
interact with messages known
as
tweets. ",
" LinkedIn "
= >
"LinkedIn is a business
and
employment -oriented service
that operates via websites
and
mobile apps. ");
$websites
[
" Instagram "
] =" Instagram is a photo
and
video-sharing
social networking service owned by Facebook, Inc. ";
foreach
(
$websites
as
$key
= >
$value
) {
echo
" $key: $value
"
;
}
?>
Output: Example 2.Using shorthand $websites
= [
"Facebook"
= >
"Facebook, Inc. is an online social
media
and
social networking service company. ",
"Twitter"
= > "Twitter is a microblogging
and
social networking service
on which users post
and
interact with messages known
as
tweets. ",
"LinkedIn"
= > "LinkedIn is a business
and
employment-oriented service that operates via websites
and
mobile apps. "];
$websites
[
" Instagram "
] = "Instagram is a photo
and
video-sharing
social networking service owned by Facebook, Inc. ";
foreach
(
$websites
as
$key
= >
$value
) {
echo
"
$key: $value
"
;
}
?>
Output: