Q:

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

belongs to collection: PHP Array Programs

0

Syntax:

    array_values(array);

It accepts an array and returns a new array having only values from given array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

PHP code to get the only values from an associative array

<?php
    //array with keys and values
    $arr = array("name" => "Amit", "age" => 21, "Gender" => "Male");
    
    //creating a new array with values of $arr
    $new_arr = array_values($arr);
    
    //printing new array
    print_r ($new_arr);
?>

Output

Array
(
    [0] => Amit
    [1] => 21
    [2] => Male
)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP program to sort an integer array in ascending ... >>
<< Create an associative array in PHP...