PHP Array Function

What is array Function?

Explanation

The "array" function is used to create an array. The elements of array is ordered map which associates values to keys

Syntax:


array(key => value)

In the above syntax each array elements is created with a key and value. If the key is skipped the function will automatically assign a numerical key starting from "0".

Example :


<?php
$b=array("1"=>"Cherry","2"=>"Apple");
print_r($b);
?>
Result :

Array ( 1 => Cherry 2 => Apple )

In the above example an array "$b" is created with keys "1" ,"2" and values "Cherry", "Apple".

PHP Topics


Ask Questions

Ask Question