How to get the only values from an associative array in PHP?

PHP array_values() function example: Here, we will figure out how to get the main values from a cooperative exhibit in PHP?

Given a cluster with keys, values and we need to make an exhibit with the main values.

Getting the main values from a cluster

To extricate the main values from an acquainted exhibit, we use array_values() function, it restores another cluster with numeric files (beginning from 0 records) and values.



It acknowledges an exhibit and returns another cluster having just values from a given cluster.

PHP code to get the main values from an acquainted exhibit

    //array with keys and values
    $arr = array("name" => "Kishan", "age" => 26, "Gender" => "Male");
    //creating a new array with values of $arr
    $new_arr = array_values($arr);
    //printing new array
    print_r ($new_arr);


    [0] => Kishan
    [1] => 26
    [2] => Male

Leave a Comment

error: Alert: Content is protected!!