PHP array() Function (original) (raw)

Last Updated : 20 Jun, 2023

The array() function is an inbuilt function in PHP which is used to create an array. There are three types of array in PHP:

Parameters: This function accepts atmost two parameters as mentioned above and described below:

Return Value: This function returns an array of parameters. Below programs illustrates the array() function in PHP:Program 1: This example illustrate the Indexed array.

php `

len=count(len = count( len=count(sub ); // Loop to print array elements for( i=0;i = 0; i=0;i < len;len; len;i++) { echo sub[sub[sub[i] . "\n"; } ?>

`

Output:

DBMS Algorithm C++ JAVA

Program 2: This example illustrate the Associative array.

php `

"GeeksforGeeks", "Address"=>"Noida", "Type"=>"Educational site"); // Display the output var_dump ($detail); ?>

`

Output:

array(3) { ["Name"]=> string(13) "GeeksforGeeks" ["Address"]=> string(5) "Noida" ["Type"]=> string(16) "Educational site" }

Program 3: This example illustrate the Multidimensional array.

php `

`

Output:

array(2) { [0]=> array(4) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) } [1]=> array(4) { [0]=> int(5) [1]=> int(6) [2]=> int(7) [3]=> int(8) } }