<?php $contacts = [/* a few Contact entities in there */]; // ExampleA $names = retrieve_names($contacts); $isPrimaryContact = is_primary_contact($contacts); $countries = retrieve_countries($contacts); // It is easy to provide simple functions: this makes both the calling code easy to read // and each functions, `retrieve_name` and co. easy to implement. // BUT, this comes at a cost: instead of having a O(n) operation you make it a O(3n) because // in each function you would iterate over the array once more. // ExampleB: a more performant alternative. Depending of the logic that needs to be crammed there // it can easily become a lot less readable. $names = []; $isPrimaryContact = false; $countries = []; foreach($contacts as $contact) { $names[] = $contact->name; $isPrimaryContact = $isPrimaryContact || $contact->isPrimary; $countries[] = $contact->address->country; }
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`