TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

PHP Array Functions

PHP array functions for beginners and professionals with examples, php file, php session, php date, php array, php form, functions, time, xml, ajax, php mysql, regex, string, oop

<< Back to PHP

PHP Array Functions

PHP provides various array functions to access and manipulate the elements of array. The important PHP array functions are given below.

1) PHP array() function

PHP array() function creates and returns an array. It allows you to create indexed, associative and multidimensional arrays.

Syntax

array array ([ mixed $... ] )

Example

  

Output:

Season are: summer, winter, spring and autumn

2) PHP array_change_key_case() function

PHP array_change_key_case() function changes the case of all key of an array.

Note: It changes case of key only.

Syntax

array array_change_key_case ( array $array [, int $case = CASE_LOWER ] )

Example

"550000","Vimal"=>"250000","Ratan"=>"200000");  
print_r(array_change_key_case($salary,CASE_UPPER)); 
?>  

Output:

Array ( [SONOO] => 550000 [VIMAL] => 250000 [RATAN] => 200000 )

Example

"550000","Vimal"=>"250000","Ratan"=>"200000");  
print_r(array_change_key_case($salary,CASE_LOWER)); 
?>  

Output:

Array ( [sonoo] => 550000 [vimal] => 250000 [ratan] => 200000 )

3) PHP array_chunk() function

PHP array_chunk() function splits array into chunks. By using array_chunk() method, you can divide array into many parts.

Syntax

array array_chunk ( array $array , int $size [, bool $preserve_keys = false ] )

Example

"550000","Vimal"=>"250000","Ratan"=>"200000");  
print_r(array_chunk($salary,2)); 
?>  

Output:

Array ( 
[0] => Array ( [0] => 550000 [1] => 250000 ) 
[1] => Array ( [0] => 200000 )
)

4) PHP count() function

PHP count() function counts all elements in an array.

Syntax

int count ( mixed $array_or_countable [, int $mode = COUNT_NORMAL ] )

Example

  

Output:

4

5) PHP sort() function

PHP sort() function sorts all the elements in an array.

Syntax

bool sort ( array &$array [, int $sort_flags = SORT_REGULAR ] )

Example

";  
}  
?>  

Output:

autumn
spring
summer
winter

6) PHP array_reverse() function

PHP array_reverse() function returns an array containing elements in reversed order.

Syntax

array array_reverse ( array $array [, bool $preserve_keys = false ] )

Example

";  
}  
?>  

Output:

autumn
spring
winter
summer

7) PHP array_search() function

PHP array_search() function searches the specified value in an array. It returns key if search is successful.

Syntax

mixed array_search ( mixed $needle , array $haystack [, bool $strict = false ] )

Example

  

Output:

2

8) PHP array_intersect() function

PHP array_intersect() function returns the intersection of two array. In other words, it returns the matching elements of two array.

Syntax

array array_intersect ( array $array1 , array $array2 [, array $... ] )

Example

";  
}  
?>  

Output:

sonoo
smith
Next TopicPHP String




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf