How to retrieve an array from Multidimensional Array.
Posted
by
Mike Smith
on Stack Overflow
See other posts from Stack Overflow
or by Mike Smith
Published on 2011-01-09T18:48:52Z
Indexed on
2011/01/09
18:53 UTC
Read the original article
Hit count: 404
So I have a multi-dimensional array looks like this.
$config = array(
"First Name" => array(
"user" => $_POST['firstname'],
"limit" => 35,
),
"Last Name" => array(
"user" => $_POST['lastname'],
"limit" => 40,
),
);
I want use the array that's within the config array, so my approach is to use a foreach loop.
foreach($config as $field => $data) {
}
Now I know that $data will be my array, but it seems I can't use it outside of the foreach statement because I only get half of whats already there. Using print_r you can see what it shows outside the loop:
Array
(
[user] => lastname
[limit] => 40
)
But when inside the loop and I use print_r here is my result:
Array
(
[user] => firstname
[limit] => 35
)
Array
(
[user] => lastname
[limit] => 40
)
I imagine it has to do something with it being with the foreach loop. I've tried to run a foreach on the $data array to populate another array, but that didn't work as well.
Is there a way to use this outside of a foreach loop?
Sorry if this a dumb question, I'm sure there is a quite a simple answer to this, but I'm just stumped, and can't think of a way to do this. Thanks.
© Stack Overflow or respective owner