Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8999693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:12:50+00:00 2026-06-16T00:12:50+00:00

Below is a sample of the structure of the array. I need to be

  • 0

Below is a sample of the structure of the array. I need to be able to pull out specific values such as : [245][subfields][a]. There are a variable number of [fields] and a variable number of [subfields] inside each of the array. Thanks for any suggestions!

Edit: I have included the array in its navtive JSON format that I am retrieving. I was then using json_decode to convert this into a usable array in php. If you have a better suggestion, please let me know.

Link to pretty array

{"leader":"01220nam  2200265   4500","fields":[{"001":"ocm00000197"},{"005":"19880526181046.0"},{"008":"690325r19681924nyua          00000 eng  "},{"010":{"ind1":" ","ind2":" ","subfields":[{"a":"67-020193 \/\/r832"}]}},{"035":{"ind1":" ","ind2":" ","subfields":[{"a":".b10000021"},{"b":"a    "},{"c":"-"}]}},{"041":{"ind1":"1","ind2":" ","subfields":[{"a":"eng"},{"a":"fre"}]}},{"049":{"ind1":" ","ind2":" ","subfields":[{"a":"JBLA"},{"c":"$8.00"}]}},{"100":{"ind1":"1","ind2":"0","subfields":[{"a":"Allemagne, Henry Ren\u00e2e d',"},{"d":"1863-1950."}]}},{"245":{"ind1":"1","ind2":"0","subfields":[{"a":"Decorative antique ironwork :"},{"b":"a pictorial treasury \/"},{"c":"by Henry Ren\u00e2e d'Allemagne ; introd., bibliography, and translation of captions by Vera K. Ostoia."}]}},{"260":{"ind1":"0","ind2":" ","subfields":[{"a":"New York :"},{"b":"Dover Publications,"},{"c":"[1968]"}]}},{"300":{"ind1":" ","ind2":" ","subfields":[{"a":"x, 415 p. :"},{"b":"(chiefly ill.) ;"},{"c":"31 cm."}]}},{"500":{"ind1":" ","ind2":" ","subfields":[{"a":"\"This Dover edition ... is a republication of all the plates in the two portfolios of Mus\u00e2ee Le Secq des Tournelles \u00e1a Rouen: Ferronnerie ancienne, originally published ... in 1924.\""}]}},{"500":{"ind1":" ","ind2":" ","subfields":[{"a":"\"Other books by Henry Ren\u00e2e d'Allemagne\": p. x."}]}},{"590":{"ind1":" ","ind2":" ","subfields":[{"a":"1373336."}]}},{"650":{"ind1":" ","ind2":"0","subfields":[{"a":"Art metal-work."}]}},{"700":{"ind1":"1","ind2":"0","subfields":[{"a":"Ostoia, Vera K."}]}},{"710":{"ind1":"2","ind2":"0","subfields":[{"a":"Mus\u00e2ee Le Secq des Tournelles."}]}},{"830":{"ind1":" ","ind2":"0","subfields":[{"a":"Dover pictorial archive series."}]}},{"999":{"ind1":" ","ind2":" ","subfields":[{"b":"1"},{"c":"901102"},{"d":"m"},{"e":"b"},{"f":"-"},{"g":"0"}]}},{"945":{"ind1":" ","ind2":" ","subfields":[{"a":"739.4\/ALLEMAGNE,H"},{"g":"1"},{"i":"31184001373336"},{"l":"abx7 "},{"n":"moved from RESEARCH collection - Feb 2012"},{"o":"-"},{"p":"$8.00"},{"s":"-"},{"t":"235"},{"u":"10"},{"v":"0"},{"w":"0"},{"x":"1"},{"y":".i10000021"},{"z":"901102"}]}}]}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:12:50+00:00Added an answer on June 16, 2026 at 12:12 am

    So it looks like you’ll need a method to loop over the fields key to check the first key of each of its sub-arrays to match your searched item.

    // Loop over the fields, which are each arrays numerically indexed...
    foreach ($record['fields'] as $key => $field) {
      // Get the field's first array key, which is 010, 015, etc...
      $marc_keys = array_keys($field);
      // the first key...
      $marc_field = $marc_keys[0];
      // Note in PHP 5.4 you could dereference it more easily like
      // $marc_field = array_keys($field)[0];
    
      // Test if the key you found is the one you want...
      if ($marc_field == '245') {
         foreach ($field[$marc_field]['subfields'] as $subkey => $subfield) {
           // Get the subfield identifier (the first array key)
           $sf_keys = array_keys($subfield);
           $sf_identifier = $sf_keys[0];
           if ($sf_identifier == 'a') {
              // Congratulations Arthur, you found the grail....
              // Do something with it...
           } 
         }
      }
      // Otherwise, keep looping until you find the one you need...
    }
    

    As a function:

    You are best served to convert this to a function that accepts the $field,$subfield as parameters:

    Updated to account for multiple subfields of the same type, and return an array:

    function getSubfield($record, $in_field, $in_subfield) {
        // Array to hold output for multiple like subfields
        $subfields_returned = array();
    
        foreach ($record['fields'] as $key => $field) {
          $marc_keys = array_keys($field);
          $marc_field = $marc_keys[0];
    
          // Test if the key you found is the one you want (which is the $in_field param)
          if ($marc_field == $in_field) {
             foreach ($field[$marc_field]['subfields'] as $subkey => $subfield) {
    
               $sf_keys = array_keys($subfield);
               $sf_identifier = $sf_keys[0];
    
               // And match the subfield to the function param $in_subfield
    
               if ($sf_identifier == $in_subfield) {
                  // Congratulations Arthur, you found the grail....
                  // Return it...
                  $subfields_returned[] = $subfield[$sf_identifier];
               }
             }
              // After the subfield loop, you can return the accumulated array
             if (count($subfields_returned) > 0) return $subfields_returned;
          }
          // Otherwise, keep looping until you find the one you need...
        }
    }
    

    Here is a demonstration

    …With a record I cobbled together partially…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Check out the small html structure sample below for context. Check out this fiddle
I have a large multidimensional array structured like the sample below. [ ['name' =>
I have the below structure in my SWIG interface file and thusly my sample.h
I have a sample 2d $tasks array which describes a nested structure : Array
I am using a very simple structure, mapping, as defined below: struct mapping{ int
I have below sample data. AID Date Title ----- ---------- ------ 1 2011-12-12 test1
I've put together a small code-sample below (Currently in C# 3.5 but would also
I have a IObservable [named rows in the sample below] from Reactive extensions framework
I am trying to binary serialize the data of vector. In this sample below
Below is a sample implementation that uses metro API and data binding (using MVVM)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.