php-marc
php-marc copied to clipboard
How to loop through all sub fields of a field
Thanks for the great code.
How can I loop through all subfields of a field. For example the field 505 is generally used to store table of contents of a book. It has a,t,g,r sub fields. Is it possible to loop through all sub fields of 505 and check sub field name. something like:
foreach ($field as $subfield) {
if ($subfield == "g") {
...
}
}
Here's an example:
foreach ($record->getFields("505") as $field) {
foreach ($field->getSubfields() as $subfield) {
if ($subfield->getCode() === "t") {
...
}
}
}
A general tip is to autocomplete "get" to get an overview of available methods: