Home »
PHP
PHP array_values() Function with example
PHP array_values() function: Here, we are going to learn about the array_values() function with example in PHP.
Submitted by IncludeHelp, on February 21, 2019
PHP array_values() function
array_values() function is used to get the only values from an array, it returns an array of the values with numeric keys (indexing starts with 0).
It is useful, when we need an array with only values.
Syntax:
array_values(array1);
It accepts an array and returns a new array with only values.
Examples:
Input:
$arr = array("a" => "Hello", "b" => "Hi!", "c" => "Bye!");
Output:
Array
(
[0] => Hello
[1] => Hi!
[2] => Bye!
)
PHP code:
<?php
//array with keys
$arr = array("a" => "Hello", "b" => "Hi!", "c" => "Bye!");
//creating array with only values
$new_arr = array_values($arr);
//printing
print_r ($new_arr);
?>
Output
Array
(
[0] => Hello
[1] => Hi!
[2] => Bye!
)
TOP Interview Coding Problems/Challenges