Voting

: max(two, seven)?
(Example: nine)

The Note You're Voting On

CommentUser
7 years ago
The following code, which returns back a flattened array of sorts into the $results array, in newer versions of PHP raises the error "PHP Fatal error: Call-time pass-by-reference has been removed":

<?php

$results
= array();

function
example_function ($item, $key, &$arr_values)
{
$arr_values[$key] = $item;
}

array_walk_recursive($data, 'example_function', &$results);

print_r($results);

?>

This can be fixed using an anonymous function:

<?php

$results
= array();

array_walk_recursive($data, function ($item, $key) use (&$results){$results[$key] = $item;});

print_r($results);

?>

<< Back to user notes page

To Top