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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.