php在数组中查找正值和负值的最大值

I have an array i want to find max value for both positive and negative value. The expected result would be -13.2 and 7.8

$array = array
(
    [0] => -13.2
    [1] => -14.5
    [2] => -14.3
    [3] => -13.7
    [4] => -13.8
    [5] => -14.6
    [6] => 6.4
    [7] => 6.9
    [8] => 7.2
    [9] => 6.9
    [10] => 7.8
    [11] => 6.9
    [12] => 6.3
    [13] => 7.2
    [14] => 6.9
    [15] => 6.8
)

$maxrl='';
for($i=1,$j=0;$i<=count($array);$i++,$j++)
    {
        if($maxr <= $array[$j])
            {
                if(($maxr < $array[$j]) && ($maxrl != ''))
                    {
                        $maxrl='';
                        $maxrl.="L".$k.",";
                    }
                else
                    {
                        $maxrl.="L".$k.",";
                    }
                $maxr = $max_array[$j];

            }
        $k++;
    }
echo "<tr><td >'.$maxr.'</td><td>'.substr($maxrl,0,-1).'</td><>/tr>";

PHP has max and min methods specifically for this

$max = max($array); // 7.8
$min = min($array); // -14.6

You can simply use max & min functions,

echo "Max Value:- ".max($array); // Max Value:-  7.8
echo "Min Value:- ".min($array); // Min Value:- -14.6

UPDATED: If you really want max from both negative & positive values,

$positive = array_filter($array, function ($v) {
  return $v > 0;
});

$negative = array_filter($array, function ($v) {
  return $v < 0;
});

echo "Max in positive Value:- ".max($positive); // Max in positive Value:-  7.8
echo "Min in negative Value:- ".min($negative); // Max in negative Value:- -13.2

Just do:

$max = max($array);
$min = min($array);

Much easier! ;)

For the positive maximum just take

$max = max($array);

The highest minimum is a bit more complex:

$minArray = array();
foreach ( $array as $val )
    if ( $val < 0 )
       $minArray[] = $val;

$min = max($minArray);

If I get the OPs question right

//$dd = array(-50, -25, -5, -80, -40, -152, -45, -28, -455, -100, -98, -455);
$dd = array(50, -25, -5, 80, -40, -152, -45, 28, -455, 100, 98, -455);
//$dd = array(50, 25, 5, 80, 40, 152, 45, 28, 455, 100, 98, 455);
$curr = '';
$max = $dd[0];

for($i = 0; $i < count($dd); $i++) {
    $curr = $dd[$i];

    if($curr >= $max) {
        $max = $curr;   
    }
}

echo "greatest number is $max";