Danny620 Posted January 19, 2012 Share Posted January 19, 2012 How do i ouput it like this Array ( [Griffin] => Array ( [0] => Peter [1] => Lois [2] => Megan ) [Quagmire] => Array ( [0] => Glenn ) [brown] => Array ( [0] => Cleveland [1] => Loretta [2] => Junior ) ) rather than this Array ( [field_name] => first_name [field_type] => 1 [max_length] => 20 ) Array ( [field_name] => last_name [field_type] => 1 [max_length] => 40 ) Array ( [field_name] => email [field_type] => 1 [max_length] => 80 ) $fields = array(); foreach ($_POST['use'] as $field){ $fields = array( "field_name"=>$field, "field_type"=>$match_types[$i], "max_length"=>$match_length[$i]); print_r($fields); echo $fields[0]['field_name']; //echo $field.' - Type: '.$match_types[$i].' - Lenght: '.$match_length[$i]."<br />"; $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/255358-multidimensional-arrays-php-foreach/ Share on other sites More sharing options...
ManiacDan Posted January 19, 2012 Share Posted January 19, 2012 Those two arrays have nothing to do with each other. If you're asking how to get the newlines and spacing, echo a <pre> tag before your print_r and that will maintain the format of pre-formatted text. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/255358-multidimensional-arrays-php-foreach/#findComment-1309226 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.