Create PHP Arrays
In PHP, you can create arrays using the array()
function or the shorthand syntax []
.
Example of Creating Arrays
<?php
$colors = array("red", "green", "blue");
$fruits = ["apple", "banana", "orange"];
print_r($colors);
print_r($fruits);
?>
Output:
Array
(
[0] => red
[1] => green
[2] => blue
)
Array
(
[0] => apple
[1] => banana
[2] => orange
)
Explanation: This example demonstrates two ways to create arrays in PHP: using the array()
function and the shorthand syntax.