PHP Arrays
PHP arrays can be indexed (numeric keys) or associative (string keys). They can hold any type, including other arrays.
Creating Arrays
Short syntax [] (PHP 5.4+) or array().
PHP arrays can be indexed (numeric keys) or associative (string keys). They can hold any type, including other arrays.
Short syntax [] (PHP 5.4+) or array().
<?php
// Indexed
$fruits = ["apple", "banana", "cherry"];
echo $fruits[0]; // apple
// Associative
$user = [
"name" => "Alice",
"email" => "alice@example.com",
"age" => 25,
];
echo $user["name"]; // Alice
// Mixed
$mixed = [1, "two", true, null, ["nested"]];
print_r($mixed);
?>