Howdy,
I was wondering if it is possible to loop through a multidimensional array using the foreach function.
The array in question is structured as such:
Array
(
[1] => Array
(
[key1] => value
[key2] => value
[key3] => value
[key4] => value
[key5] => value
[key6] => value
[key7] => value
)
The first array is a numerical index with the second array representing a row of data to be loaded in to a database. I want to loop through the main array and for each index output each key => value pair then upload to database and repeat.
Is this possible with a foreach statement?
Quick Array question
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Quick Array question
Assuming your array is called $array:
-Shawn
Code: Select all
foreach($array as $data) {
foreach($data as $key => $value) {
echo $key . " = " . $value;
}
}mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
-
Katsu Webs
- Forum Newbie
- Posts: 5
- Joined: Fri Dec 04, 2009 2:20 pm
Re: Quick Array question
Ah ha,
many thanks Shawn code now working nicely!
many thanks Shawn code now working nicely!