-2

Would anyone be able to update this deprecated piece of code for PHP 7.2. I have found many similar questions and answers, but can't figure out how to convert this particular piece of code.

array_walk($_REQUEST['categories'], create_function('&$c', '$c = "-" . $c;'));
profundiz
  • 1
  • 1
  • Does this answer your question? [PHP 7.2 Function create\_function() is deprecated](https://stackoverflow.com/questions/48161526/php-7-2-function-create-function-is-deprecated) – Progman Apr 11 '21 at 15:28

1 Answers1

0

You can use an anonymous function.

array_walk($_REQUEST['categories'], function(&$c) { $c = "-" . $c; });

Example

$array = ['a','b','c'];
array_walk($array, function(&$c) { $c = "-" . $c; });
print_r($array);

Will produce

Array
(
    [0] => -a
    [1] => -b
    [2] => -c
)