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

How to loop through all sub fields of a field #24

Open
hackerspk opened this issue Jan 17, 2023 · 1 comment
Open

How to loop through all sub fields of a field #24

hackerspk opened this issue Jan 17, 2023 · 1 comment

Comments

@hackerspk
Copy link

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") {
...
}

}
@danmichaelo
Copy link
Member

danmichaelo commented Feb 27, 2024

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:

image

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