ARRAY In PHP - Types of Array in PHP



ARRAY


An array stores multiple values in one single variable:

Here we are showing that how can we create a array in PHP, Types of array in PHP, 

<!DOCTYPE html><html><body>
<?php$cars=array("Volvo","BMW","Toyota"); echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";?>
</body></html>


In PHP, there are three types of arrays:
  • Indexed arrays - Arrays with numeric index
  • Associative arrays - Arrays with named keys
  • Multidimensional arrays - Arrays containing one or more arrays

PHP Indexed Arrays

There are two ways to create indexed arrays:
The index can be assigned automatically (index always starts at 0):

<!DOCTYPE html><html><body>
<?php$cars=array("Volvo","BMW","Toyota"); echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";?>
</body></html>

Get The Length of an Array - The count() Function

<!DOCTYPE html>
<html>
<body>

<?php
$cars=array("Volvo","BMW","Toyota");
echo count($cars);
?>


</body>
</html>


Tags: array function in php,array push php,define array in php,multidimensional array in php,storing data in array in php,creation of associative array in php,php array key value,usage of array in php

Post a Comment

Previous Post Next Post