When using the Podio PHP API and after getting an item collection using:
$item_collection = PodioItem::filter( $app_id, $attributes );
How can I get the value(s) of a field with an external_id
of, for example, email
?
Currently I loop through all the items like this:
$items = [];
foreach ($item_collection as $item) {
$email = "";
foreach ( $item->fields as $field ) {
if( $field->external_id == "email") {
$email = trim($field->values);
} //repeat for each field eg 'name'
}
$items[] = array (
'email' => $email,
'name' => $name //etc
);
}
Is there a way to directly get the field value without looping through all the fields in the whole collection of items?
Using PodioItem::get_field_value
obviously makes another request which seems counter to getting all the items from PodioItem::filter
.
break
to stop the foreach-loop after you found the attribute for a small performance boost – fehrlich