PHP array

Array in PHP
PHP arrays are powerful tools for storing multiple values within a single variable. This capability allows developers to organize data efficiently, accessing elements through indexes, which can be either numeric or string-based keys. An array is essentially a collection of variables, each referred to as an element. These elements can be directly retrieved using their specific indexes, simplifying data manipulation and retrieval in PHP programming.

Array Creation and Initialization

FunctionDetails
Creating an ArrayHow to create and assign keys
array_fill_keys()Create array by filling keys and value
array_fill()Filling an array with value
array_column()Displaying one column data of an array
Multidimensional ArrayCreating and displaying elements of Multidimensional array
array_range Create array using a range with optional step value
Breaking string We can split a string and create a array by using all words.

Displaying, Checking and counting elements

FunctionDetails
array_count_values calculate the frequency of occurrence of elements inside a array
Displaying elementsListing all elements of the array
array_is_list() checks if an array is a list
is_array To check the variable is array or not
array_size() How many elements are present inside the array? We can find out by count or sizeof() function.
array_max() Maximum minimum value present inside array
array_rand Randomly collecting elements of an array
array_sum Total value or sum of the elements present inside an array
array_shuffle randomizes the order of the elements of an array

Array Modification

FunctionDetails
array_chunk()Split an array into chunks
array_change_key_case()Changing keys to upper case or lower case chars
array_splice()Modifying Arrays in PHP
array_replace()Replace the values of the array
array_replace_recursive()Merge Arrays Recursively
array_walk()Passing user defined function to each element of an array
array_walk_recursive()Traversing multi-dimensional array

Array Sorting

FunctionDetails
SortingSorting all elements of an array by sort command
array_multisort()Sorting Multiple Arrays
usort()Sort the elements using a user-defined function

Array Searching

FunctionDetails
in_array()Check the presence of an element inside an array. Returns True or False
array_search()Returns the key if matching found, FALSE otherwise
array_key_exists()Search Key, returns TRUE if found, FALSE otherwise
array_keys()Returns an array of keys
array_key_first()Get the first key of the array (>= PHP 7.3)
array_key_last()Get the last key of the array (>= PHP 7.3)

Array Filtering and Extraction

FunctionDetails
array_filter()Creating new array using filter (callback) function
array_reduce()Iteratively reduces an array to a single value
array_map()Apply native or user-defined functions to each element
array_unique()Set of unique values from an array

Array Merging and Combining

FunctionDetails
array_merge()Add one array to another
array_merge_recursive()Merge arrays recursively
array_combine()Create an array with keys from one and values from another

Array Intersection

FunctionDetails
array_diff()Generate a third array by differentiating two arrays
array_diff_assoc()Generate a third array by differentiating two arrays (keys and values)
array_intersect()Intersection of arrays considering values only
array_intersect_assoc()Intersection of arrays considering keys and values
array_intersect_key() Intersection of arrays considering keys only
array_intersect_uassoc() Intersection of arrays considering keys & values through callback function
array_intersect_ukey() Intersection of arrays considering keys through callback function
array_uintersect intersection of arrays with Custom Comparison
array_udiff_uassoc compare arrays based on custom rules
array_uintersect_uassoc Intersect Arrays with Custom Data and Key Comparisons
array_uintersect_assoc array intersections with custom value comparison

Array Difference

FunctionDetails
array_diff_uassoc Resultant third array by differentiating values and (keys through callback function)
array_diff_ukey Resultant third array by comparing keys through callback function
array_udiff Resultant third array by comparing values through callback function
array_diff_key We can generate a resultant third array by differentiating two arrays by considering keys only

Array Adding & Removing Elements

FunctionDetails
array_pop() Removing last element of the array
array_shift() Removing first element of the array
array_unset() Removing element from any position
array_push() Adding elements at the end
array_unshift() Adding elements at the beginning

Array Traversing & Navigation

FunctionDetails
CurrentGet the current element of the array
NextMove to the next element
PreviousMove to the previous element
EndMove to the last element
ResetMove to the first element

Array Form Handling and Session Management

FunctionDetails
Array checkbox Getting checkbox value using array
http_build_query generate query string using elements to pass through URL
Session array create a session array and carry same data across the pages.
function Passing and returning array from a function
Cookies Cookies array adding and deleting elements

Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer