mercredi 8 février 2017

Creating a collection from a multidimensional array?

I'm trying to make a collection from some arrays of data:

$myCollection = collect(
    ['product_id' => 1, 'price' => 200, 'discount' => '50'],
    ['product_id' => 2, 'price' => 400, 'discount' => '50']
);

When I loop out I would like to do:

foreach ($myCollection as $product) {
    echo $product->price;
    echo $product->discount;
}

But the underlying elements appear to still be in an arrays format, how can I achieve the above output?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2lqGzQS
via IFTTT

Aucun commentaire:

Enregistrer un commentaire