Jump to content

how to get all elements of array


jasonc

Recommended Posts

I am able to get all elements but the 'i*'  parts.

 

How do I do this.

 

$formarray = array(
'name' => array(
	'i1'=>		array('a'=>'a1', 'b'=>'b1', 'c'=>'c1', 'd'=>'d1', 'e'=>'e1', 'f'=>'f1', 'g'=>'g1'),
	'i2'=>		array('a'=>'a2', 'b'=>'b2', 'c'=>'c2', 'd'=>'d2', 'e'=>'e2', 'f'=>'f2', 'g'=>'g2'),
	'i3'=>		array('a'=>'a3', 'b'=>'b3', 'c'=>'c3', 'd'=>'d3', 'e'=>'e3', 'f'=>'f3', 'g'=>'g3'),
	'i4'=>		array('a'=>'a4', 'b'=>'b4', 'c'=>'c4', 'd'=>'d4', 'e'=>'e4', 'f'=>'f4', 'g'=>'g4'),
	)
);

foreach ($formarray as $newarray => $a) {
	?><strong><?=$newarray;?></strong><br><?
  				foreach ($a as $key => $k) {
				foreach ($k as $b) {
					?>"<?=$b;?>", <?
				}
				?><br><?
			} //end of second foreach
	?><br><br><br><?
} //end of first foreach
?>

Link to comment
https://forums.phpfreaks.com/topic/212675-how-to-get-all-elements-of-array/
Share on other sites

not sure if u are looking for they i1,i2... here is way to get key value with $key

<?php

$formarray = array(
'name' => array(
	'i1'=>		array('a'=>'a1', 'b'=>'b1', 'c'=>'c1', 'd'=>'d1', 'e'=>'e1', 'f'=>'f1', 'g'=>'g1'),
	'i2'=>		array('a'=>'a2', 'b'=>'b2', 'c'=>'c2', 'd'=>'d2', 'e'=>'e2', 'f'=>'f2', 'g'=>'g2'),
	'i3'=>		array('a'=>'a3', 'b'=>'b3', 'c'=>'c3', 'd'=>'d3', 'e'=>'e3', 'f'=>'f3', 'g'=>'g3'),
	'i4'=>		array('a'=>'a4', 'b'=>'b4', 'c'=>'c4', 'd'=>'d4', 'e'=>'e4', 'f'=>'f4', 'g'=>'g4'),
	)
);

foreach ($formarray as $newarray => $a) {
	?><strong><?=$newarray;?></strong><br><?
  				foreach ($a as $key => $k) {
			?>"<?=$key;?>", <?
				foreach ($k as $b) {
					?>"<?=$b;?>", <?
				}
				?><br><?
			} //end of second foreach
	?><br><br><br><?
} //end of first foreach
?>

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.