如何创建依赖于三元运算符的 td id?

How to td id create depend on the ternary operator?

  $orientationData = explode('_', $generate_table['orientation']);
  foreach ($orientationData as $orientationData1) {
     $get_ori= $this->o->get_orientation($orientationData1);
     $table_row[$td++] = array('data' => $get_ori, 'style' => 'text-align:center;','class'=>'editable', $orientationData1>0?'id'=>$orientationData1);
  }

$orientationData 就像 1,2,3,4,0,0,0,8,9; 当给定 'id'=>$orientationData1 id 名称生成为 1,2,3,4,0,0,0,8,9 我希望它生成时不带零

foreach ($orientationData as $orientationData1) {
    $get_ori= $this->o->get_orientation($orientationData1);
    if($orientationData1>0){
        $table_row[$td++] = array('data' => $get_ori, 'style' => 'text-align:center;','class'=>'editable','id'=>$orientationData1);
    }else{
        $table_row[$td++] = array('data' => $get_ori, 'style' => 'text-align:center;','class'=>'editable');
    }
}

这些结果没问题..请告诉我另一种方法?

您可以使用 array_filter()(http://php.net/array_filter) 从数组中删除 0。如果您不为该函数提供回调,它会删除 0 和 'false' 值。

  $orientationData = explode('_', $generate_table['orientation']);
  $orientationData = array_filter($orientationData);
  foreach ($orientationData as $orientationData1) {
     $get_ori= $this->o->get_orientation($orientationData1);
     $table_row[$td++] = array('data' => $get_ori, 'style' => 'text-align:center;','class'=>'editable', $orientationData1>0?'id'=>$orientationData1);
  }