php - How to understand this magic: "array_values() expects parameter 1 to be array, array given"?
366
Here is my simple code:
$item['suppliers'] = array_values($item['suppliers']);
And here is PHP error log:
[22-May-2019 13:05:23 Europe/Moscow] PHP Warning: array_values() expects parameter 1 to be array, array given in /var/www/xxx/Controller.php on line 242
[22-May-2019 13:07:06 Europe/Moscow] PHP Warning: array_values() expects parameter 1 to be array, array given in /var/www/xxx/Controller.php on line 242
[22-May-2019 13:07:45 Europe/Moscow] PHP Warning: array_values() expects parameter 1 to be array, array given in /var/www/xxx/Controller.php on line 242
Answer
Solution:
$item['suppliers'] might be an item in an array but not an array which is why the error is thrown.
You should put your array name inside array_values() function.
So Correct code will be:
$item['suppliers'] = array_values($item);
Answer
Solution:
$item['suppliers'] is not array .array_values require array parameter .
Maybe u want do as below