Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 2 years ago.
0

Are you opposed to using a for loop? Because you could write one to accomplish this.

Last updated 2 years ago.
0

Isn't this bad for the performance?

Last updated 2 years ago.
0

It looks like you've already got the data from the database. That's the most important thing in regards to performance, and if you are doing that well, this part shouldn't affect performance. For Loops from my understanding are the fastest iterative construct that PHP has to offer - it doesn't hurt to try and optimize later.

$count = count($buildings);

for($i = 0; $i < $count; $i++ ) {
    if ($buildings[$i]->building_data->building_data_id == 5) {
        return $buildings[$i];
    }
}

return 'no buildings of id 5';
Last updated 2 years ago.
0

okay, thank you :)

Last updated 2 years ago.
0

No problem, glad I could help

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

d3mueller d3mueller Joined 29 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.