![]() |
Useful PHP Functions To Work With Arrays
The in-built array functions allow you to interact with and manipulate arrays in various ways. Arrays are essential for storing, managing, and operating on sets of variables.
Simple and multi-dimensional arrays are supported, and may be either user created or created by another function. There are specific database handling functions for populating arrays from database queries, and several functions return arrays. You can read more about working with PHP arrays here. In this article I'll demonstrate a few important and useful php functions, you can read and refer to the whole list of PHP functions on the official PHP website. array_push()Inserts one or more elements to the end of an array. Code: PHP
array_pop()Deletes the last element of an array. Code: PHP
array_shift()Removes the first element from an array, and returns the value of the removed element. Code: PHP
array_unshift()Adds one or more elements to the beginning of an array. Code: PHP
array_unique()Removes duplicate values from an array.array_unique() takes input array and returns a new array without duplicate values. Code: PHP
in_array()Checks if a value exists in an array. Code: PHP
array_walk()Apply a user function to every member of an array. Code: PHP
array_combine()Creates an array by using one array for keys and another for its values. Code: PHP
end()Sets the internal pointer of an array to its last element.This function can be used to get the last element of an array. Code: PHP
|
Re: Useful PHP Functions To Work With Arrays
ALl scripts are very fine, do you have some idea about associative arrays and ksort() function as i tried to learn it but was unable to understand it , kindly help me on the topic
|
Re: Useful PHP Functions To Work With Arrays
What exactly do you want to know?
|
Re: Useful PHP Functions To Work With Arrays
Its a nice post abt PHP array functions
really like it |
Re: Useful PHP Functions To Work With Arrays
Hi Pradeep,
You wrote a wonderful scripts.It included PHP array function also. I appreciate to you..Thanks for your sharing also... |
Re: Useful PHP Functions To Work With Arrays
There are two kinds of arrays in PHP: indexed and associative. The keys of an indexed array are integers, beginning at 0. Indexed arrays are used when you identify things by their position. Associative arrays have strings as keys and behave more like two-column tables. The first column is the key, which is used to access the value.PHP internally stores all arrays as associative arrays, so the only difference between associative and indexed arrays is what the keys happen to be. Some array features are provided mainly for use with indexed arrays, because they assume that you have or want keys that are consecutive integers beginning at 0. In both cases, the keys are unique--that is, you can't have two elements with the same key, regardless of whether the key is a string or an integer.PHP arrays have an internal order to their elements that is independent of the keys and values, and there are functions that you can use to traverse the arrays based on this internal order. The order is normally that in which values were inserted into the array, but the sorting functions described later let you change the order to one based on keys, values, or anything else you choose.
|
Re: Useful PHP Functions To Work With Arrays
Like arrays in other languages, PHP arrays allow you to store multiple values in a single variable and operate on them as a set. PHP offers an extensive array manipulation toolkit—over 60 functions—that lets you process arrays in almost any way imaginable including reversing them, extracting subsets, comparing and sorting, recursively processing, and searching them for specific values.
his document outlines some of the more useful functions in the PHP array with explanations and usage examples: Function:- sizeof($arr) array_values($arr) array_keys($arr) array_pop($arr) array_push($arr, $val) array_shift($arr) array_unshift($arr, $val) each($arr) sort($arr) array_flip($arr) array_reverse($arr) array_merge($arr) array_rand($arr) array_search($search, $arr) array_slice($arr, $offset, $length) array_unique($data)array_walk($arr, $func) |
Re: Useful PHP Functions To Work With Arrays
ok,thx for your sharing
|
Re: Useful PHP Functions To Work With Arrays
Here is much more detailed description of PHP array functions: php.net/manual/en/book.array.php
|
Re: Useful PHP Functions To Work With Arrays
Just to kill this topic:)
|
| All times are GMT +5.5. The time now is 21:49. |