Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
array
value
communitycreator

What is the array_values method in PHP?

Programming Bytes

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The array_values method in PHP returns all of the values of the arraya data structure that contains a group of elements.

Syntax

array_values($array): array

Return type

The array_values method returns an array.

Code

Example 1

<?php 

$age_array = array("Rahum" => 12, "Ram" => 22);

print_r( array_values( $age_array));
?>

Explanation

In the code above, we create an array with the name age_array and call the array_values method.

The array_values method returns a new array with all values of age_array. The indexing of the returned array will be based on default numeric indexing.

Example 2

<?php 

$multi_array = array(
                        'one' => 1,
                        'two' => array('one' => 2, 'two' => 22)
                    );
print_r( array_values( $multi_array));

?>

Explanation

In the above code, we create a multidimensional array with multi_array and call the array_values method. The array_values method will return a new array with all values of multi_array.

RELATED TAGS

php
array
value
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring