PHP Student PHP Student - 15 days ago 9
PHP Question

array_filter on PHP 7

I have a few lines of codes that will convert array values to uppercase. This work fine on my local development server using PHP 5.6, however it fails using PHP 7.0. What is causing it to fail?

function make_uppercase(&$word) {
$word = strtoupper ( $word );
return $word;
}

$fish = array (
"hampala ampalong",
"hampala macrolipedota"
);
print_r ( array_filter ( $fish, "make_uppercase" ) );

Answer

You should write this. This will solve your problem

function make_uppercase(&$word) {
        $word = strtoupper ( $word );
        return $word;
    }

    $fish = array (
            "hampala ampalong",
            "hampala macrolipedota" 
    );
    print_r ( array_map ( "make_uppercase", $fish  ) );