array as a variable php code example
Example 1: php declare array
$arr = array(
'v1',
'v2',
'v3'
);
$arr = [
'v1',
'v2',
'v3'
];
$arr = array(
'k1' => 'v1',
'k2' => 'v2',
'k3' => 'v3'
);
$arr = [
'k1' => 'v1',
'k2' => 'v2',
'k3' => 'v3'
];
Example 2: assign array to variable php
$info = array('coffee', 'brown', 'caffeine');
list($drink, $color, $power) = $info;
echo "$drink is $color and $power makes it special.\n";
list($drink, , $power) = $info;
echo "$drink has $power.\n";
list( , , $power) = $info;
echo "I need $power!\n";
list($bar) = "abcde";
var_dump($bar);