xxxxxxxxxx
// Define Array
$fruits = array("apple", "banana", "orange");
// Outputs "apple"
echo $fruits[0];
// This will output the elements of the array one by one:
// apple, banana, orange.
foreach ($fruits as $fruit) {
echo $fruit;
}
xxxxxxxxxx
<?php
$array = array(
"foo" => "bar",
"bar" => "foo",
);
// as of PHP 5.4
$array = [
"foo" => "bar",
"bar" => "foo",
];
?>
xxxxxxxxxx
<?php
$array = array(
"foo" => "bar",
"bar" => "foo",
);
// as of PHP 5.4
$array = [
"foo" => "bar",
"bar" => "foo",
];
?>
xxxxxxxxxx
<?php
$numbers=array(1,3,4,5,6);
// array multidimensional
$users = [
[
"id"=>1,
"name"=>"andi",
"point"=>10,
],
[
"id" => 2,
"name" => "nana",
"point" => 15,
], [
"id" => 3,
"name" => "mawar",
"point" => 10,
],
[
"id" => 4,
"name" => "yono",
"point" => 10,
]
];
xxxxxxxxxx
<?php
$array = array(
"foo" => "bar",
"bar" => "foo",
);
// Utilisant la syntaxe de tableau courte
$array = [
"foo" => "bar",
"bar" => "foo",
];
?>
xxxxxxxxxx
<?php
$fruits = array (
"fruits" => array("a" => "orange", "b" => "banana", "c" => "apple"),
"numbers" => array(1, 2, 3, 4, 5, 6),
"holes" => array("first", 5 => "second", "third")
);
?>
xxxxxxxxxx
<?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"]);
?>
xxxxxxxxxx
<?php
$array = array("foo", "bar", "hello", "world");
var_dump($array);
?>
xxxxxxxxxx
<?php
$array = array(
"foo" => "bar",
"bar" => "foo",
);
// Utilisant la syntaxe de tableau courte
$array = [
"foo" => "bar",
"bar" => "foo",
];
?>
xxxxxxxxxx
<?php
$array = array(
"foo" => "bar",
"bar" => "foo",
);
// Using the short array syntax
$array = [
"foo" => "bar",
"bar" => "foo",
];
?>