Skip to content

Instantly share code, notes, and snippets.

@Sankame
Last active August 6, 2016 15:09
Show Gist options
  • Save Sankame/4389910 to your computer and use it in GitHub Desktop.
Save Sankame/4389910 to your computer and use it in GitHub Desktop.
[isset通過処理] 値を取り出す際のissetによる条件分岐を省略する。
<?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