PHP array_values() Function with example

array_values() work is utilized to get the main qualities from a cluster, it restores a variety of the qualities with numeric keys (ordering begins with 0).

It is helpful when we need an exhibit with just qualities.

Syntax:

array_values(array1);

Example

 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! 
)

Recent Posts

error: Alert: Content is protected!!