0

I created a code that working perfectly in my localhost, however when I put a server appear this error: Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ',' or ') This is the code:

<?php
    $csv1 = array();
    $csv2 = array();
    // check there are no errors
    if($_FILES['csv1']['error'] == 0 && $_FILES['csv2']['error'] == 0){
        $name1 = $_FILES['csv1']['name'];
        $name2 = $_FILES['csv2']['name'];
        $ext1 = strtolower(explode('.', $_FILES['csv1']['name'])[1]);
        $ext2 = strtolower(explode('.', $_FILES['csv2']['name'])[1]);
        $type1 = $_FILES['csv1']['type'];
        $type2 = $_FILES['csv2']['type'];
        $tmpName1 = $_FILES['csv1']['tmp_name'];
        $tmpName2 = $_FILES['csv2']['tmp_name'];

        // check the file is a csv
        if($ext1 == 'csv' && $ext2 == 'csv'){
            if(($handle1 = fopen($tmpName1, 'r')) != FALSE && ($handle2 = fopen($tmpName2, 'r')) != FALSE) {
                // necessary if a large csv 
                $i = 0;
                while(($data1 = fgetcsv($handle1, 1024, ',')) != FALSE) {
                    if(sizeof($data1) > 1){
                        $dna1[$i] = $data1[1];
                        $i = $i + 1;
                    }
                }
                fclose($handle1);
                $i = 0;
                while(($data2 = fgetcsv($handle2, 1024, ',')) != FALSE) {
                    if(sizeof($data2) > 1){
                        $dna2[$i] = $data2[1];
                        $i = $i + 1;
                    }
                }
                fclose($handle2);
            }
            $dna = array_intersect($dna1, $dna2);
            $dna = array_filter($dna, fn($value) => !is_null($value) && $value != '');
            echo '<div align = "center"';
            foreach ($dna as $key => $value) {
                if ($key > 0)
                    echo ''.$value.'';
                    echo '<br>';
            }
            echo '</div>';
        }else{
            echo "Esse arquivo não é csv!";
        }
        
    }   
?>

The error is in $dna = array_filter($dna, fn($value) => !is_null($value) && $value != '');, I do not know how to solve this problem. Someone can help me? If you want to teste web site:

https://rrodrigofranco.000webhostapp.com/dna

Rodrigo
  • 37
  • 4
  • 1
    What version of PHP is the server running, the above needs 7.4 at least (https://www.php.net/manual/en/functions.arrow.php) – Nigel Ren Oct 05 '21 at 07:22
  • Thanks bro. The version of the PHP of the serve was 7.2. Now I upadted the version and working my script. – Rodrigo Oct 05 '21 at 15:40

0 Answers0