PHP array_values()

php sort array by value

php sort array by value() The array_values()Β  is an inbuilt function in PHP and return the array of values from the another given array. Given array may be associative array (key – value) pairs or indexed array. This function return an array.

php sort array by value() Syntax

array array_values ($array)

$array: This argument refers to the main array in which you want to fetch the values.

Return Value: This function will return an array of values like indexed array.

Example 1

<?php
$arr = array("james" => 15, "david" => 18, "smith" => 34);
print_r(array_values($arr));
?>

Output

Array 
( 
 [0] => 15 
 [1] => 18 
 [2] => 34 
)

Example 2

<?php
$arr = array("david","james","john","smith");
print_r(array_values($arr));
?>

Output

Array 
( 
 [0] => david 
 [1] => james 
 [2] => john 
 [3] => smith 
)

More Related Post

Thanks for the reading post. I hope you like and understand the post. If you have any doubt regarding this post please comment below.

Leave a comment

Your email address will not be published. Required fields are marked *