define array php code example
Example 1: ccreate array php
$array = array(
"foo" => "bar",
"bar" => "foo",
);
Example 2: array php
<?php
$array = array(
"foo" => "bar",
"bar" => "foo",
);
$array = [
"foo" => "bar",
"bar" => "foo",
];
?>
Example 3: array key value php
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
foreach($age as $x=>$x_value)
{
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>
Example 4: 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 5: array php
<?php
$array = array(
"foo" => "bar",
"bar" => "foo",
);
$array = [
"foo" => "bar",
"bar" => "foo",
];
?>
Example 6: 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"]);
?>