-2

I got this array:

enter image description here

What I want to do next is to make a collection from the array and I write:

$variant_images = collect($p->images); 

but I got the error:

"Undefined index: images"

What's bad in my code and how to solve it?

codedge
  • 4,754
  • 2
  • 22
  • 38
Aleks Per
  • 1,549
  • 7
  • 33
  • 68

1 Answers1

1

Assuming $p is array like this

$p = [
  'images' => [
    1, 2, 3, 4
  ]
];

you can write

$collection = collect($p);

// access the images
var_dump($collection->get('images'));

and the output would be

array:4 [▼
  0 => 1
  1 => 2
  2 => 3
  3 => 4
]
codedge
  • 4,754
  • 2
  • 22
  • 38