Jump to content

Multidimensional Arrays php foreach


Danny620

Recommended Posts

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++;
	  
      }

Link to comment
https://forums.phpfreaks.com/topic/255358-multidimensional-arrays-php-foreach/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.