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

enter image description here

331

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);

836

Answer

Solution:

$item['suppliers'] is not array .array_values require array parameter .


if(is_array($item['suppliers'])
{
$item['suppliers'] = array_values($item['suppliers);

}

Maybe u want do as below


$item['suppliers']=array_values($item);

People are also looking for solutions to the problem: php - Not getting data from webservice

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.