PHP array is an ordered map (contains value on the basis of the key). It is used to hold multiple values of a similar type in a single variable.
Advantage of PHP Array
Arrays are complex variables that allow us to store more than one value or a group of values under a single variable name. Let's suppose you want to store colors in your PHP script. Storing the colors one by one in a variable could look something like this:
Example :
<?php
$day1= "Sunday";
$day2 = "Monday";
$day3 = "Tuesday";
?>
If you want to store the states or city names of a country in variables and this time this not just three maybe a hundred. It is quite hard, boring, and a bad idea to store each city name in a separate variable. And here array comes into play.
In PHP, the array() function is used to create an array:
array();
There are three types of arrays that you can create. These are:
© 2024 Easy To Learning. All Rights Reserved | Design by Easy To Learning