I am wondering what I am doing wrong in the following code, because I get error: Warning: Illegal offset type in isset or empty in D:\xampp\htdocs\testing\4.php on line 5 $_POST[firstkey][secondkey]=12; if (isset($_POST)) { foreach($_POST as $key){ foreach ($_POST[$key] as $key2 => $value){ echo "<br />Key=".$key2."value=".$value; } } } PHP: How would be the correct was echo in the same statement 1st and 2nd key and value? Thank you
I think you want something like this: $_POST[firstkey][secondkey]=12; if (isset($_POST)) { foreach($_POST as $key=>$value){ if (is_array($value)) { foreach ($value as $key2 => $value2){ echo "<br />First Key= ".$key. "Second Key=".$key2." value=".$value2; } } else { echo "<br />Key=".$key." value=".$value; } } } PHP: