array functions in php Introduction. PHP array() function creates and returns an array.
array functions in php – PHP Array Functions
array functions in php – there are the list of the Commonly used PHP5 Array Functions Like as array_slice($arr, $offset, $length), array_rand($arr), array_reverse($arr), array_flip($arr), array_map(‘function_name’, $arr), sort($arr), array_shift($arr), array_push($arr, $val), array_pop($arr), array_keys($arr), array_values($arr), array_merge($arr1, $arr2), print_r($arr), in_array($var, $arr), is_array($arr) and sizeof($arr).
sizeof($arr)
Example
Results
Size of the array is: 3
is_array($arr)
Example
Results
Array
not an Array
in_array($var, $arr)
Example
Results
Not yet!
Don’t Miss : PHP associative array push
print_r($arr)
Example
Results
Array (
[0] => “Uday”
[1] => “Hitesh”
[2] => “Avantika”
)
array_merge($arr1, $arr2)
Example
"India", "Bhumika" => "Fukky", "Devraj" => "Swarg", "Movie" => "Tamil" ); $members = array("Vishal", "Jayshree", "Naveent", "Sanjay"); $merged = array_merge($exam_pass_list, $members); print_r($merged); ?>
Results
Array ( [Krishna] => India [Bhumika] => Fukky [Devraj] => Swarg [Movie] => Tamil [0] => Vishal [1] => Jayshree [2] => Naveent [3] => Sanjay )
Don’t Miss : PHP check if value exists in associative array
array_values($arr)
Example
"India", "Bhumika" => "Fukky", "Devraj" => "Swarg", "Movie" => "Tamil" ); // members who own the above members $members = array("Vishal", "Jayshree", "Naveent", "Sanjay"); // let's merge the two arrays into one $merged = array_merge($exam_pass_list, $members); //getting only the values $merged = array_values($merged); print_r($merged); ?>
Results
Array ( [0] => India [1] => Fukky [2] => Swarg [3] => Tamil [4] => Vishal [5] => Jayshree [6] => Naveent [7] => Sanjay )
array_keys($arr)
Example
Results
Array ( [0] => Krishna [1] => Bhumika [2] => Devraj [3] => Movie [4] => 0 [5] => 1 [6] => 2 [7] => 3 )
array_pop($arr)
Example
Results
Array ( [0] => Uday [1] => Hitesh )
array_push($arr, $val)
Example
Results
Array ( [0] => Uday [1] => Hitesh [2] => Avantika [3] => Ella )
Don’t Miss : Php filter multidimensional array by multiple values
array_shift($arr)
Example
Results
Array ( [0] => Hitesh [1] => Avantika )
sort($arr)
Example
Results
Array ( [0] => Avantika [1] => Ella [2] => Hitesh [3] => Uday )
array_map(‘function_name’, $arr)
Example
Results
Array ( [0] => 11 [1] => 21 [2] => 31 [3] => 41 [4] => 51 )
array_flip($arr)
Example
"India", "Bhumika" => "Fukky", "Devraj" => "Swarg", "Movie" => "Tamil" ); print_r(array_flip($exam_pass_list)); ?>
Results
Array ( [India] => Krishna [Fukky] => Bhumika [Swarg] => Devraj [Tamil] => Movie )
array_reverse($arr)
Example
Results
Array ( [0] => 50 [1] => 40 [2] => 30 [3] => 20 [4] => 10 )
Don’t Miss : PHP array functions
array_rand($arr)
Example
Results
member of the day: grishna
array_slice($arr, $offset, $length)
Example
Results
Array ( [0] => bhumi [1] => grishna [2] => waqdur )
Don’t Miss : PHP array functions with examples
I hope you get an idea about array functions in php.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.