Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

array_filter on PHP 7

Tags:

arrays

php

filter

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" ) );
like image 312
PHP Student Avatar asked Jan 24 '26 11:01

PHP Student


1 Answers

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  ) );
like image 113
Jahid Mahmud Avatar answered Jan 27 '26 01:01

Jahid Mahmud



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!