Jump to content

Archived

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

Danny620

Multidimensional Arrays php foreach

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

×

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.