-1

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

Zoe
  • 27,060
  • 21
  • 118
  • 148

2 Answers2

0

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

Shweta
  • 661
  • 6
  • 11
  • No. No. No. I have $item['suppliers'], I have $item['total'], I have $item['min]. So I need exactly $item['suppliers']. I can't past var_dump() response, but $item is a simple array of arrays and $item['suppliers'] is a simple array of arrays. – Mikhail Radomskiy May 22 '19 at 11:33
  • if $item['suppliers'] is an array of an array, then you can at least let us know which item of an array $item['suppliers'] you want to pull out in new $item['suppliers']. Hope you are understanding the mechanism of array_values. array_values expect an array (only) as a parameter, not an array of an array or only single value or string anything. So you have to pass an array only as a parameter. – Shweta May 22 '19 at 12:25
  • I want to get the same array, but without keys. This is what this function is for. – Mikhail Radomskiy May 22 '19 at 14:03
  • Until you provide dummy data and the format of the data you want, it's hard to explain. But just to answer your query, array_values works for fetching values from single array, not for fetching values from multidimensional array, so you to pass single array to array values() by traversing your $item['suppliers'] in loop may be. – Shweta May 23 '19 at 05:39
0

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

dılo sürücü
  • 3,821
  • 1
  • 26
  • 28