Forum Moderators: coopster

Message Too Old, No Replies

get keys of multi level array

         

php_member

1:00 pm on Jun 21, 2009 (gmt 0)

10+ Year Member



I get values of $_POST from previous page where names of inputs are set automatically, so I don't know those names.

The following code print the error:
Warning: Illegal offset type in isset or empty in D:\xampp\htdocs\testing\4.php on line 5

[PHP]
$_POST[firstkey][secondkey]=12;
if (isset($_POST)) {
foreach($_POST as $firstkey){
foreach ($_POST[$firstkey] as $secondkey => $value){
echo $firstkey.$secondkey.$value
}
}
}
[/PHP]

How would be the correct way to get 1st key, 2nd key and value?

Thank you

Pico_Train

1:19 pm on Jun 21, 2009 (gmt 0)

10+ Year Member



maybe try ...

if (isset($_POST))
{
foreach($_POST as $1key=>post)
{
foreach($post as $2key=>$value)
{
echo $1key.$2key.$value;
}
}
}