-
-
/** - * 二次元配列を走査
- * bbs.it-home.org を編集
- */
- //ループトラバーサル用
- $arr2=array(array("張三","20","男性") ,array("李四","25","男性"),array("王五","19","女性"),array("趙劉","25","女性"));
- echo "
名前 | 年齢 | 性別 | ";
- for($i=0;$iecho "
";- for($j=0;$j<3;$j++){
- echo "< td>";
- echo $arr2[$i][$j];
- echo "";
- }
- echo "
"; - echo "
" ; - }
- echo "
";
- ?>
//foreach traversal
- $arr = array('one'=>array('name'=> ;'Zhang San','age'=>'23','sex'=>'男性'),
- 'two'=>array('name'=>'李思','age' => '43','性別'=>'女性'),
- '3'=>array('名前'=>'王五','年齢'=>'32','性別 '=> ;'男性'),
- 'four'=>array('名前'=>'趙劉','年齢'=>'12','性別'=>'女性')) ;< /p>
foreach($arr as $k=>$val){
- echo $val['name'].$val['age'].$val['sex'] ."< ;br>";
- }
- echo "
";
//foreach トラバーサルの例 2
- $arr = array('one'=>array(' name'= >'張三','年齢'=>'23','性別'=>'男性'),
- 'two'=>array('名前'=>'李思' ,'年齢'=>'43','性別'=>'女性'),
- 'three'=>array('名前'=>'王五','年齢'=>'32 ',' sex'=>'男性'),
- 'four'=>array('name'=>'趙劉','年齢'=>'12','性別'=>'女性') );
- foreach($arr as $key=>$value){
- foreach($value as $key2=>$value2){
- echo $value2;
- }
- echo "
"
- ?>
-
-
-
コードをコピー
|