Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

PHP Array

PHP Array Introduction

Array functions in PHP allow you to access and manipulate arrays, supporting both simple and multi-dimensional arrays.

Installation

Array functions are built into the PHP core, so no installation is required to use them.

PHP Array Functions

Function

Description

array()

Creates an array

array_change_key_case()

Transforms all keys in an array to lowercase or uppercase

array_chunk()

Divides an array into smaller chunks

array_column()

Extracts the values from a specified column in the input array

array_combine()

Generates an array by combining elements from a “keys” array and a “values” array

array_count_values()

Counts the occurrences of all values in an array

array_diff()

Compares arrays and returns the differences based on their values only

array_diff_assoc()

Compares arrays and returns the differences based on both keys and values

array_diff_key()

Compares arrays and returns the differences based on keys only

array_diff_uassoc()

Compares arrays and returns the differences based on both keys and values, using a custom key comparison function

array_diff_ukey()

Compares arrays and returns the differences based on keys only, using a custom key comparison function

array_fill()

Populates an array with values

array_fill_keys()

Populates an array with values, assigning specific keys

array_filter()

Filters the values of an array based on a callback function

array_flip()

Swaps all keys with their corresponding values in an array

array_intersect()

Compares arrays and returns the matching values only

array_intersect_assoc()

Compares arrays and returns the matches based on both keys and values

array_intersect_key()

Compares arrays and returns the matches based on keys only

array_intersect_uassoc()

Compares arrays and returns the matches based on both keys and values, using a custom key comparison function

array_intersect_ukey()

Compares arrays and returns the matches based on keys only, using a custom key comparison function

array_key_exists()

Checks if the given key is present in the array

array_keys()

Returns all the keys from an array

array_map()

Passes each value of an array to a user-defined function, which returns new values

array_merge()

Combines one or more arrays into a single array

array_merge_recursive()

Recursively combines one or more arrays into a single array

array_multisort()

Sorts multiple arrays or multi-dimensional arrays

array_pad()

Adds a specified number of items with a given value to an array

array_pop()

Removes the last element from an array

array_product()

Computes the product of all the values in an array

array_push()

Appends one or more elements to the end of an array

array_rand()

Returns one or more random keys from an array

array_reduce()

Converts an array to a string using a custom function

array_replace()

Replaces the values of the first array with the values from subsequent arrays

array_replace_recursive()

Recursively replaces the values of the first array with the values from subsequent arrays

array_reverse()

Returns an array with its elements in reverse order

array_search()

Searches an array for a specific value and returns the corresponding key

array_shift()

Removes the first element from an array and returns the value of the removed element

array_slice()

Returns specific segments of an array

array_splice()

Removes and replaces designated elements in an array

array_sum()

Calculates the sum of the values in an array

array_udiff()

Compares arrays and returns the differences based on values only, using a custom key comparison function

array_udiff_assoc()

Compares arrays and returns the differences based on both keys and values, using a built-in function for key comparison and a user-defined function for value comparison

array_udiff_uassoc()

Compares arrays and returns the differences based on both keys and values, using two custom key comparison functions

array_uintersect()

Compares arrays and returns the matches based on values only, using a custom key comparison function

array_uintersect_assoc()

Compares arrays and returns the matches based on both keys and values, using a built-in function for key comparison and a user-defined function for value comparison

array_uintersect_uassoc()

Compares arrays and returns the matches based on both keys and values, using two custom key comparison functions

array_unique()

Eliminates duplicate values from an array

array_unshift()

Inserts one or more elements at the start of an array

array_values()

Returns all the values from an array

array_walk()

Applies a user-defined function to each element of an array

array_walk_recursive()

Recursively applies a user-defined function to each element of an array

arsort()

Sorts an associative array in descending order based on its values

asort()

Sorts an associative array in ascending order based on its values

compact()

Create an array that includes variables and their corresponding values

count()

Returns the count of elements in an array

current()

Returns the current element of an array

each()

Deprecated since PHP 7.2. Returns the current key-value pair from an array

end()

Moves the internal pointer of an array to its last element

extract()

Imports variables from an array into the current symbol table

 in_array()

 Checks whether a specified value is present in an array

key()

Retrieves a key from an array

krsort()

Sorts an associative array in descending order based on its keys

ksort()

Sorts an associative array in ascending order based on its keys

list()

Assigns values to variables as if they were elements of an array

natcasesort()

Sorts an array using a case-insensitive “natural order” algorithm

natsort()

Sorts an array using a “natural order” algorithm

next()

Moves the internal array pointer forward

pos()

An alias for current()

prev()

Resets the internal array pointer to the beginning

range()

Generates an array containing a sequence of elements

reset()

Resets the internal pointer of an array to its initial element.

rsort()

Arranges the elements of an indexed array in descending order.

shuffle()

Randomly rearranges the elements of an array

sizeof()

Alternative name for count()

sort()

Sorts an indexed array in increasing order.

uasort()

Sorts an array based on its values using a custom comparison function while preserving the index associations

uksort()

Sorts an array by its keys using a custom comparison function.

usort()

Sorts an array based on its values using a user-defined comparison function.