php - check value if null return 0 otherwise return the value -


what shortest way set if status null return '0' else return value.

$value['status'] = null;  $statuses = array(     0 => 'pending',     1 => 'accepted',     2 => 'suspended',     3 => 'rejected',     4 => 'waiting list',     5 => 'terminated',     9 => 'application in progress' );  $status = $statuses[$value['status']];  echo $status; 

i can use empty() function check if value 'null' wanted know if there smarter way.

i looking native function this.

$status = $statuses[ valuetoziro( $value['status'] )];  function valuetoziro($val){     return empty($val)?0:$val; } 

if sure getting integer $value['status'] can cast integer, shorter:

// in case of null, casting return 0 $status = $statuses[(int)$value['status']]; 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -