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

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -