Get All Values from an Associative Array using foreach Loop
The basic approach is to use a foreach loop to iterate over the associative array and access each value.
<?php
$student = array(
"Maths" => 95,
"Physics" => 90,
"Chemistry" => 96,
"English" => 93,
"Computer" => 98
);
foreach ($student as $marks) {
echo "$marks\n";
}
?>
Output
95 90 96 93 98
How to Get All Values from an Associative Array in PHP?
Given an Associative Array, the task is to get all values from the associative array in PHP. To get all the values from an associative array, you can use various approaches such as foreach loop, array_values() function, and array_map() function. In this article, we will explore each approach with detailed explanations and code examples.
Table of Content
- Using foreach Loop
- Using array_values() Function
- Using array_map() Function
Contact Us