Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

foreach not use as object same example #74

Closed
hoangnamitc opened this issue May 4, 2019 · 1 comment
Closed

foreach not use as object same example #74

hoangnamitc opened this issue May 4, 2019 · 1 comment

Comments

@hoangnamitc
Copy link

Hi,

I'm push 1 array from PHP via bladeOne.

I foreach it,

`
@foreach ($array as $item)

{{ $item->id }} (not working)

{{ $item['id'] }} (working)

@Endforeach
`

Why?

Thanks!

@jorgecc
Copy link
Member

jorgecc commented May 4, 2019

It is because you are not parsing an array of object but an array of arrays

Array objects

$obj=new stdClass();
$obj->id=1;
$obj->name="john";
$arrObject=[$obj,$obj];
@foreach($arrayobjects as $item)
    item:{{$item->id}} {{$item->name}}<br>
@endforeach

Array of arrays

$arr=['id'=>1,'name'=>'John'];
$arrays=[$arr,$arr];
@foreach($arr as $item)
    item:{{$item['id']}} {{$item['name']}}<br>
@endforeach

@jorgecc jorgecc closed this as completed May 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants