3

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" ) );
Special Sauce
  • 5,338
  • 2
  • 27
  • 31

2 Answers2

2

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  ) );
Jahid Mahmud
  • 1,136
  • 1
  • 12
  • 32
0

Difference between array_filter() and array_map()? You should use array_map instead of array_filter.

But I am wondering why your code has different result between PHP 5 and PHP 7. http://phpio.net/s/1bpu

Community
  • 1
  • 1
Manh Nguyen
  • 930
  • 5
  • 12