0

i have an PHP code like below. i use an array, looping, and function in my PHP code

<?php
    $array_rows = array( 50, 60, 50, 50 );
    $array_cols = array( 30, 20, 70, 30, 60 );
    $costs = array(
        array( 16, 16, 13, 22, 17 ),
        array( 14, 14, 13, 19, 15 ),
        array( 19, 19, 20, 23, 50 ),
        array( 50, 12, 50, 15, 11 )
    );

    function diff($j, $len, $is_row, $res[3]) {
        $i, $c, max($min1), $min2 = $min1, $min_p = -1;
        for($i=0; $i<$len; ++$i) {
            if(($is_row) ? $col_done[$i] : $row_done[$i]) continue;
            $c = ($is_row) ? $costs[$j][$i] : $costs[$i][$j];
            if($c < $min1) {
                $min2 = $min1;
                $min1 = $c;
                $min_p = $i;
            }
            else if($c < $min2) $min2 = $c;
        } 
        $res[0] = $min2 - $min1;
        $res[1] = $min1;
        $res[2] = $min_p;
    }

?>

but why I get an Error :

Parse error: syntax error, unexpected '[', expecting ')' in C:\UwAmp\www\v.php on line 11

can somebody help my to fix my error code?

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
  • 2
    You should use the key when calling the function, not defining it. – user3783243 Jul 25 '18 at 14:45
  • 3
    You can't take `$res[3]` as a function parameter, it doesn't make any sense. – Alex Howansky Jul 25 '18 at 14:46
  • 1
    Do you use an IDE? They can be helpful in solving some common errors in coding. – Nigel Ren Jul 25 '18 at 14:46
  • 2
    You're going to run into errors over the next few lines as well. Line 12 looks like javascript assignment syntax, which does not work with PHP. Then after that will be the unknown variables since they don't exist in scope... – aynber Jul 25 '18 at 14:49

0 Answers0