PHP Array Functions

tutorial and example
tutorial and example

There are various array functions in PHP. They are used to access and manipulate the elements ofan array.

Following are functions of array.

Array Function Description
array() It is used to create an array.
array_change_key_case() It is used to convert lowercase or uppercase of all keys in an array.
array_chunk() It is used to split an array into chunks of arrays.
array_pop() It is used to delete the last element of an array.
array_merge() It is used to merge one or more arrays into one array.
array_rand() It is used to returns one or more random keys from an array.
array_reverse() It returns an array in the reverse order.
array_search() It searches an array for a given value and returns the key.
count() It returns the number of elements in an array.
extract() It imports variables into the current symbol table from an array.
sort() PHP sort() function sorts all the elements in an array.
  • PHP array() function

PHP array()function is used to create  an array( Associate , Index and Multidimensional).

Example:

Output

=====To print Week days using an array======
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday

  • array_change_key_case() function

PHP array_change_key_case() function is used to change the case of all key of an array.

Example

Output

3). PHP array_chunk() function

PHP array_chunk() function is  used to split an array into chunks. We can divide array into many parts.

Example

Output

PHP array_pop() Function

PHP array_pop() function is used to delete last element of an array.

Example

PHP count() Function

PHP count() function is used to return the number of elements in an array.

Example

Output

4

PHP sort() Function

PHP short() function is used to sort the elements of  an array in ascending order.

Example

Output

Assending Order [27,21,83,11]
11
21
27
83