PHP provides various array functions to access and manipulate the elements of the array. The important PHP array functions are given below.

array() function

PHP array() function creates and returns an array. It allows you to create indexed, associative and multidimensional arrays.

Syntax

array array ([ mixed $… ] )

Example

<?php    

$season=array(“summer”,”winter”,”spring”,”autumn”);    

echo “Season are: $season[0], $season[1], $season[2] and $season[3]”;    

?>    

Output:

Season are: summer, winter, spring and autumn

array_change_key_case() function

The PHP array_change_key_case() function changes the case of all keys of an array.

Syntax

array array_change_key_case ( array $array [, int $case = CASE_LOWER ] )  

Example

<?php    

$salary=array(“Sonoo”=>”550000″,”Vimal”=>”250000″,”Ratan”=>”200000”);    

print_r(array_change_key_case($salary,CASE_UPPER));   

?>    

Output:

Array ( [SONOO] => 550000 [VIMAL] => 250000 [RATAN] => 200000 )

array_chunk() function

PHP array_chunk() function splits arrays into chunks. By using array_chunk() method, you can divide the array into many parts.

Syntax

array array_chunk ( array $array , int $size [, bool $preserve_keys = false ] )  

<?php    

$salary=array(“Sonoo”=>”550000″,”Vimal”=>”250000″,”Ratan”=>”200000”);    

print_r(array_chunk($salary,2));   

?>    

Output:

Array ( 

[0] => Array ( [0] => 550000 [1] => 250000 ) 

[1] => Array ( [0] => 200000 )