You are on page 1of 15

ARRAY IN PHP

1
www.apextgi.in
What is an ARRAY?
Array is a memory allocation which is used to store or contain multiple elements with unique indexes
or addresses at a continuous memory location.
With any other programming language references array is a collection of similar data types but here
in PP we can store any data type in a single array. !ecause we do not need to declare data types
before the array initiali"ation.#g$%
& www.apextgi.in
#Initilizationof an Array
'city ( array)*delhi+, *shimla+, *agra+,noida+, *patna+-.
/ndex%0 1 1 & 2 3
echo 'city415. 66 output will bedelhi
2 www.apextgi.in
Types of Array
1. 7ingle or 8ne 9imensional or 9efault or :umeric or /ndex !ase Array
&. Associati;e Array
2. <ulti 9imensional Array
3 www.apextgi.in
#Predefined Constants of an Array
CASE_LOWER )integer-:-/tis used with array=change=>ey=case)- and is used to con;ert array >eys to lower case. ?his
is also the default case forarray=change=>ey=case)-.
CASE_UPPER )integer-:- Itis used with array=change=>ey=case)- and is used to con;ert array >eys to upper case.
SORT_ASC )integer-$%SORT_ASC is used with array=multisort)- to sort in ascending order.
SORT_DESC )integer-$%SORT_DESC is used with array=multisort)- to sort in descending order.
@ www.apextgi.in
SORT_REULAR )integer-SORT_REULAR is used to compare items normally.
SORT_!U"ERIC )integer-SORT_!U"ERIC is used to compare items numerically.
SORT_STRI! )integer-SORT_STRI! is used to compare items as strings.
SORT_LOCALE_STRI! )integer-SORT_LOCALE_STRI! is used to compare items as strings, based on the current
locale. Added in PP 3.3.1 and @.1.&.
SORT_!ATURAL )integer-SORT_!ATURAL is used to compare items as strings using Anatural orderingA li>e natsort)-.
Added in PP @.3.1.
B www.apextgi.in
SORT_#LA_CASE )integer-SORT_#LA_CASE can be combined )bitwise
8R- with SORT_STRI! or SORT_!ATURAL to sort strings case%insensiti;ely. Added in PP @.3.1.
COU!T_!OR"AL )integer-
COU!T_RECURSI$E )integer-
E%TR_O$ERWRITE )integer-
E%TR_S&IP )integer-
E%TR_PRE#I%_SA"E )integer-
C www.apextgi.in
E%TR_PRE#I%_I#_E%ISTS )integer-
E%TR_I#_E%ISTS )integer-
E%TR_RE#S )integer-
E%TR_PRE#I%_ALL )integer-
E%TR_PRE#I%_I!$ALID )integer-
D www.apextgi.in
Array Functions
array=change=>ey=case E Fhanges the case of all >eys in an array
array=chun> E 7plit an array into chun>s
array column E Return the ;alues from a single column in the input array
array combine E Freates an array by using one array for >eys and another for its ;alues
array=count=;alues E Founts all the ;alues of an array
array=diff=assoc E Fomputes the difference of arrays with additional index chec>
array=diff=>ey E Fomputes the difference of arrays using >eys for comparison
G www.apextgi.in
array=diff=uassoc E Fomputes the difference of arrays with additional index chec> which is performed by a user
supplied callbac> function
array=diff=u>ey E Fomputes the difference of arrays using a callbac> function on the >eys for comparison
array=diff E Fomputes the difference of arrays
array=fill=>eys E Hill an array with ;alues, specifying >eys
array=fill E Hill an array with ;alues
array=filter E Hilters elements of an array using a callbac> function
array=flip E #xchanges all >eys with their associated ;alues in an array
11 www.apextgi.in
array=intersect=assoc E Fomputes the intersection of arrays with additional index chec>
array=intersect=>ey E Fomputes the intersection of arrays using >eys for comparison
array=intersect=uassoc E Fomputes the intersection of arrays with additional index chec>, compares indexes by a
callbac> function
array=intersect=u>ey E Fomputes the intersection of arrays using a callbac> function on the >eys for comparison
array=intersect E Fomputes the intersection of arrays
array=>ey=exists E Fhec>s if the gi;en >ey or index exists in the array
array=>eys E Return all the >eys or a subset of the >eys of an array
array=map E Applies the callbac> to the elements of the gi;en arrays
11 www.apextgi.in
array=merge E <erge one or more arrays
array=multisort E 7ort multiple or multi%dimensional arrays
array=pad E Pad array to the specified length with a ;alue
array=pop E Pop the element off the end of array
array=product E Falculate the product of ;alues in an array
array=push E Push one or more elements onto the end of array
array=rand E Pic> one or more random entries out of an array
array=reduce E /terati;ely reduce the array to a single ;alue using a callbac> function
array=replace=recursi;e E Replaces elements from passed arrays into the first array recursi;ely
array=replace E Replaces elements from passed arrays into the first array
1& www.apextgi.in
array=re;erse E Return an array with elements in re;erse order
array=search E 7earches the array for a gi;en ;alue and returns the corresponding >ey if successful
array=shift E 7hift an element off the beginning of array
array=slice E #xtract a slice of the array
array=splice E Remo;e a portion of the array and replace it with something else
array=sum E Falculate the sum of ;alues in an array
array=udiff=assoc E Fomputes the difference of arrays with additional index chec>, compares data by a callbac>
function
array=udiff=uassoc E Fomputes the difference of arrays with additional index chec>, compares data and indexes by a
callbac> function
array=udiff E Fomputes the difference of arrays by using a callbac> function for data comparison
12 www.apextgi.in
array=unique E Remo;es duplicate ;alues from an array
array=unshift EPrependone or more elements to the beginning of an array
array=;alues E Return all the ;alues of an array
array=wal>=recursi;e E Apply a user function recursi;ely to e;ery member of an array
array=wal> E Apply a user function to e;ery member of an array
array E Freate an array
arsort E 7ort an array in re;erse order and maintain index association
asort E 7ort an array and maintain index association
compact E Freate array containing ;ariables and their ;alues
count E Fount all elements in an array, or something in an obIect
current E Return the current element in an array
each E Return the current >ey and ;alue pair from an array and ad;ance the array cursor
13 www.apextgi.in
Thanks
faceboo>.com6apex.tgi
twitter.com6Apextgi:oida
pinterest.com6apextgi
Stay Connected with us for more chapters on PHP

You might also like