im feeling dont know what but i am stuck on this problem....please help how can i get the smallest number from these six variables $Price10 =23; $Price14 =43; $Price18 =29; $PriceSLV =0; $PriceGF10 =0; $PriceGF20 =0; but it should not be zero. i used min php function but it gives zero as result
i have used this sort of logic $arr = array(44,0,0,12,0,4); sort($arr); if($arr[0]!=0) { print_r($arr[0]); } elseif($arr[1]!=0) { print_r($arr[1]); } elseif($arr[2]!=0) { print_r($arr[2]); } elseif($arr[3]!=0) { print_r($arr[3]); } elseif($arr[4]!=0) { print_r($arr[4]); } else{ print_r($arr[5]); }
An idea: <?php /* $Price10 =23; $Price14 =43; $Price18 =29; $PriceSLV =0; $PriceGF10 =0; $PriceGF20 =0; */ //instead of using seperate variable, why dont use array? $price = array ( // where $price[0] = your $Price10 0 => 23, 43, 29, 0, 0, 0 ); sort($price,SORT_NUMERIC); $price = array_unique($price); if ($price[0] == 0) { $lowest = 1; // 1 = the index of array that carry the lowest value } else { $lowest = 0; // 0 = the index of array that carry the lowest value } //to use so the lowest value $use = $price[$lowest]; // debug //var_dump($price); ?> PHP: