Q:

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

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)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now