You can simply use the foreach
loop in combination with the for
loop to access and retrieve all the keys, elements or values inside a multidimensional array in PHP.
Let's take a look at the following example to understand how it basically works:
<?php
// Multidimensional array
$superheroes = array(
"spider-man" => array(
"name" => "Peter Parker",
"email" => "[email protected]",
),
"super-man" => array(
"name" => "Clark Kent",
"email" => "[email protected]",
),
"iron-man" => array(
"name" => "Harry Potter",
"email" => "[email protected]",
)
);
// Printing all the keys and values one by one
$keys = array_keys($superheroes);
for($i = 0; $i < count($superheroes); $i++) {
echo $keys[$i] . "{<br>";
foreach($superheroes[$keys[$i]] as $key => $value) {
echo $key . " : " . $value . "<br>";
}
echo "}<br>";
}
?>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Laravel 5.5 - Task Scheduling With Cron Job Example
Today, we are share in this tutorials &q...How to Make a User an Administrator in Ubuntu
While your computer is shared with your...How to Preview an Image Before it is Uploaded Using jQuery
Use the JS readAsDataURL() Method You...How to Export 10M+ records in XLSX in Laravel 7.x using rap2hpoutre/fast-excel
This post introduce FastExcel for Larave...Get Current time and date in React
In this tutorial, we will discuss how to...