PHP Array Functions

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

1) PHP array() function

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

Syntax

Example

Output:

Season are: summer, winter, spring and autumn

2) PHP array_change_key_case() function

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

Note: It changes case of key only.

Syntax

Example

Output:

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

3) PHP array_chunk() function

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

Syntax

Example

Output:

4) PHP count() function

PHP count() function counts all elements in an array.

Syntax

Example

Output: 4

5) PHP sort() function

PHP sort() function sorts all the elements in an array.

Syntax

Example

Output:

6) PHP array_reverse() function

PHP array_reverse() function returns an array containing elements in reversed order.

Syntax

Example

Output:

7) PHP array_search() function

PHP array_search() function searches the specified value in an array. It returns key if search is successful.

Syntax

Example

Output:

8) PHP array_intersect() function

PHP array_intersect() function returns the intersection of two array. In other words, it returns the matching elements of two array.

Syntax

Example

Output:

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *