数组中除0以外的PHP最小值

数组中除0以外的PHP最小值,php,min,array-filter,Php,Min,Array Filter,请帮助我找出为什么数组_diff在以下脚本提取中不起作用: $iterator_triple = (int) 3; while($new_row = $new_response->fetch_assoc()) { /*prices written into the end of array*/ $prices_listed[] = $new_row['price']; $prices_listed[] = $new_row['test']

请帮助我找出为什么数组_diff在以下脚本提取中不起作用:

$iterator_triple = (int) 3;

while($new_row = $new_response->fetch_assoc()) {

    /*prices written into the end of array*/            
    $prices_listed[] = $new_row['price'];
    $prices_listed[] = $new_row['test'];
    $prices_listed[] = $new_row['bpc'];
    $prices_length = count($prices_listed);


    while($iterator_triple < $prices_length + 1) {
        $candidates = array($prices_listed[$iterator_triple - 3], $prices_listed[$iterator_triple - 2], $prices_listed[$iterator_triple - 1]);
        print_r($candidates);
        $min_varan[] = min(array_diff($candidates, array(0)));
        $iterator_triple = $iterator_triple + 3;
    }
}
$iterator_triple=(int)3;
而($new\u row=$new\u response->fetch\u assoc()){
/*写入数组末尾的价格*/
$prices_listed[]=$new_行['price'];
$prices_listed[]=$new_row['test'];
$prices_listed[]=$new_row['bpc'];
$prices\u length=计数($prices\u列出);
而($iterator\u triple<$prices\u length+1){
$candidates=array($prices_listed[$iterator_triple-3],$prices_listed[$iterator_triple-2],$prices_listed[$iterator_triple-1]);
印刷(候选人);
$min_varan[]=min(数组差异($candidates,数组(0));
$iterator_triple=$iterator_triple+3;
}
}
我计划重写每个循环的$candidates数组,并用$minu varan数组中除0之外的最小值$candidates填充$minu varan数组。但无论是array_diff还是array_filter对我都不起作用,零总是保持不变,而我的min函数只是简单地选择它。指出我的错误

您可以假设在第一个循环期间: $candidates=array(1800019000,0)

在第二个循环中: $candidates=数组(26000、25000、24000)


因此,$min_varan[0]=0,而我希望看到18000。

您在$candidates中返回的值也是int/float类型,还是字符串?所以“0”!=0?好吧,我也尝试了array_diff($candidates,array('0'))但没有帮助。我的测试成功了。也许你的代码中有一个三元组,即数组(0,0,0),所以min(数组(0,0,0))的计算结果为null,这被添加到$min_varan中?@ThomasOster,你能再指定一点吗?“代码中的三元组”和满是零的数组是什么意思?为了让这段代码正常工作,你到底做了哪些修改?@ThomasOster,哦,请原谅我这么傻,你是对的:我只是在$candidates数组的每个元素前面加了(int),一切都很顺利。非常感谢!