Skip to content

Instantly share code, notes, and snippets.

@sugarHoge
Created June 17, 2013 07:48
Show Gist options
  • Save sugarHoge/5795265 to your computer and use it in GitHub Desktop.
Save sugarHoge/5795265 to your computer and use it in GitHub Desktop.
配列数分ループして値を取り出す方法
$test03=array(
array('111', '222'),
array('333', '444')
);
foreach ($test03 as $key1 =>$val1) {
foreach ($val1 as $key2 => $val2) {
debug($key2 . "=>" . $val2);
}
}
/*
debug: 0=>Array
debug: 0=>111
debug: 1=>222
debug: 1=>Array
debug: 0=>333
debug: 1=>444
*/
$test01[]='aaa';
$test01[]='bbb';
foreach ($test01 as $key => $val) {
debug($key . "=>" . $test01[$key]);
debug($key . "=>" . $val);
}
/*
debug: 0=>aaa content.js:73
debug: 0=>aaa content.js:73
debug: 1=>bbb content.js:73
debug: 1=>bbb
*/
$test02=array('ccc','ddd');
foreach ($test02 as $key => $val) {
debug($key . "=>" . $val);
}
/*
debug: 0=>ccc
debug: 1=>ddd
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment