-2

I'm trying to deploy php project on localhost using Winginx

Now poking around this php code

public static function compareIP( $ip, $mask )
{
    $arr1 = ( ".", $ip );
    $arr2 = ( ".", $mask );
    $good = true;
    $i = 0;
    while ( $i < ( $arr1 ) )
    {
        if ( $arr2[$i] != "*" && $arr2[$i] != $arr1[$i] )
        {
            $good = false;
            break;
        }
        ++$i;
    }
    return $good;
}

Server returns

Parse error: syntax error, unexpected ',' in C:\Winginx\home\site.com\index.php on line 54

Where line 54 is

$arr1 = ( ".", $ip );

I'm new to php and just want to deploy project, but google didn't give any hints.

I have no idea what could be wrong.

im_infamous
  • 972
  • 1
  • 17
  • 29

1 Answers1

1

I allowed myself to correct your code and tidying it a bit. Your main problem was that you were missing the array definition before putting the elements into the array. Also, in your while function you should say while $i is less than count( $arr ), as this returns the number of elements in the array in a numeric format.

public static function compareIP( $ip, $mask ){
    $arr1 = array( ".", $ip );
    $arr2 = array( ".", $mask );
    $good = true;
    $i = 0;
    while ( $i < count( $arr ) )
    {
        if ( $arr2[$i] != "*" && $arr2[$i] != $arr1[$i] ){
            $good = false;
            break;
        }
        ++$i;
    }
    return $good;
}
SharpC
  • 6,974
  • 4
  • 45
  • 40
Ole Haugset
  • 3,709
  • 3
  • 23
  • 44