Array reverse_() function
The array_reverse() function returns an array in the reverse order. This function can take one or two parameters. The first parameter is the target array to be reversed. The second optional parameter can be set to true or false.
Syntax
array_reverse (array,parameter) |
Parameters in the array reverse function:
Parameter |
Description |
array |
Optional. Possible values:
|
Example of array reverse function
<html>
<head>
<title>Array reverse_()</title>
</head>
<body>
<?php
$arr=array("2"=>1,2,3,"vinod","kumar");
$rev=array_reverse($arr);
echo "<pre>"; print_r($arr);
print_r($rev);
?>
</body>
</html>
Output
Note: According to the index of an array, such as:
[1] => vinod, [2] =>3, [3] =>2
Indexes are c, b and a (convert array value in these indexes).
Array search_() function
The array_search() function searches an array for a value and returns the key. The Search function searches for the value in an array according to the indexes. PHP will search in an array for a specific value. It is a good way to check to see if a value exists in an array.
Syntax
array_search(value,array,parameter) |
Example of array search function:
<html>
<head>
<title>array search_()</title>
</head>
<body>
<?php
$arr=array("ram"=>1,"shyam"=>5,"vinod"=>3,"sharad"=>4);
echo array_search(1,$arr,true);
?>
</body>
</html>
Output: