Last active
August 6, 2016 15:09
-
-
Save Sankame/4389910 to your computer and use it in GitHub Desktop.
[isset通過処理] 値を取り出す際のissetによる条件分岐を省略する。
This file contains 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
<?php | |
$array = array(); | |
$test = ''; | |
// 配列の要素は取り出す前にissetで確認しないとPHP Noticeが出てしまう… | |
if( isset( $array['key2'] ) ){ | |
$test = $array['key2']; | |
} | |
// if文を省略するために関数化。PHP Noticeは出ない。 | |
$test = viaIsset( $array['key2'] ); | |
/** | |
* isset通過処理 | |
*/ | |
function viaIsset( &$value ){ | |
if( isset($value) ){ | |
return $value; | |
} | |
return ''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment