creating an array in 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: array php
<?php
$array = array(
"foo" => "bar",
"bar" => "foo",
);
$array = [
"foo" => "bar",
"bar" => "foo",
];
?>
Example 3: php array
<?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"]);
?>
Example 4: array in php
<?php
$cars = array("Maserati", "Porsche", "BMW");
echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
?>