How to get all the values from an associative array in PHP

How to get all the values from an associative array in PHP

In this post we will give you information about How to get all the values from an associative array in PHP. Hear we will give you detail about How to get all the values from an associative array in PHPAnd how to use it also give you demo for it if it is necessary.

Use the PHP array_values() function

You can use the PHP array_values() function to get all the values of an associative array.

Let’s try out an example to understand how this function works:

<?php
$cities = array("France"=>"Paris", "India"=>"Mumbai", "UK"=>"London", "USA"=>"New York");
 
// Get values from cities array
print_r(array_values($cities));
?>

You can also use the PHP foreach loop to find or display all the values, like this:

<?php
$cities = array("France"=>"Paris", "India"=>"Mumbai", "UK"=>"London", "USA"=>"New York");
 
// Loop through cities array
foreach($cities as $key => $value){
    echo $key . " : " . $value . "<br>";
}
?>

 

Hope this code and post will helped you for implement How to get all the values from an associative array in PHP. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US