我正在尝试根据非空的查询结果设置一个数组。反过来,我希望以某种方式创建基于 NON Null 结果的排名。
SQL 查询返回:
Comp1 Comp2 Comp3 Comp4 Comp5 Comp6 Comp7 Comp8 Comp9
NULL NULL 226.97 274 NULL 208 189 NULL 198.99
我的PHP:
$COMP1 = $rankresult['Comp1'];
$COMP2 = $rankresult['Comp2'];
$COMP3 = $rankresult['Comp3'];
$COMP4 = $rankresult['Comp4'];
$COMP5 = $rankresult['Comp5'];
$COMP6 = $rankresult['Comp6'];
$COMP7 = $rankresult['Comp7'];
$COMP8 = $rankresult['Comp8'];
$COMP9 = $rankresult['Comp9'];
这不起作用,因为我试图只放入非 Null 的变量:
$myarray = 'array(
if(!empty($COMP1)){
$COMP1,}
if(!empty($COMP2)){
$COMP2,}
if(!empty($COMP3)){
$COMP3,}
if(!empty($COMP4)){
$COMP4,}
if(!empty($COMP5)){
$COMP5,}
if(!empty($COMP6)){
$COMP6,}
if(!empty($COMP7)){
$COMP7,}
if(!empty($COMP8)){
$COMP8,}
if(!empty($COMP9)){
$COMP9})';
期望的输出:
$myarray = array(226.97,274,208,189,198.99)