0

Hello, everyone. I am using badwords-filter npm and it is using create_function().
But as you know that function is removed from php 8.
So it is getting error now and I can't sure how to fix it.
If you are familiar with it, please help me.

    private function flattenArray($array)
    {
        $objTmp = (object)['aFlat' => []];

        array_walk_recursive($array, create_function('&$v, $k, &$t', '$t->aFlat[] = $v;'), $objTmp);

        return $objTmp->aFlat;
    }

On the above code, the create_function() is getting error.

Maksim
  • 21
  • 4
  • read the `array_walk_recursive` synatx. https://www.w3schools.com/php/func_array_walk_recursive.asp or in https://www.php.net/manual/en/function.array-walk-recursive.php – Abdulla Nilam Sep 22 '22 at 11:35
  • Thanks. But can you please help me how can I change the above code? I am new to it. – Maksim Sep 22 '22 at 11:40
  • As well as the linked duplicates, [the PHP manual page for create_function](https://www.php.net/create_function) has some information about how to use anonymous functions in its place. – IMSoP Sep 22 '22 at 11:53

0 Answers0