ds1379551 2014-09-08 13:43
浏览 62
已采纳

PHP简写跳过变量赋值

I am using this shorthand in a function to set a variable to NULL if it is not set. How can I simply not set it?

function createArray($rows){
 $array = array();

 $array['id'] = isset($rows['UnitId']) ? $rows['UnitId'] : NULL ;

}
  • 写回答

2条回答 默认 最新

  • douwen5741 2014-09-08 13:46
    关注

    Just don't set it in the first place

    function createArray($rows){
     $array = array();
    
     if(isset($rows['UnitId'])) $array['id'] = $rows['UnitId'];
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?