Last active
August 29, 2015 14:22
-
-
Save tadasuke/a89e544c466e2132d88e to your computer and use it in GitHub Desktop.
PHPで連想配列をforeachで回した時のkeyの型 ref: http://qiita.com/tadasuke/items/52e6a02d9af813443e17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$array = array( '1' => 'hoge' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach ( $array as $key => $value ) { | |
if ( $key === '1' ) { | |
echo( 'ゲッツ!!' ); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach ( $array as $key => $value ) { | |
if ( $key === 1 ) { | |
echo( 'ゲッツ!!' ); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$array = array( | |
'1' => 'hoge' | |
, 1 => 'fuga' | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array( [1] => fuga ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$array = array(); | |
$array[] = 'hoge'; | |
$array[] = 'fuga'; | |
$array['1'] = 'foo'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array( [1] => fuga ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$array = array(); | |
$array[] = 'hoge'; | |
$array[] = 'fuga'; | |
$array['1'] = 'foo'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array( [0]=>hoge [1]=>foo ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array( [0]=>hoge [1]=>foo ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment