0

This is a JSON response Array Snippet i am working on the array has about 300 plus elements i am focusing on the technologies array. I am using PHP i have tried both Foreach and for loops i can't seem to find the right sauce to get it cycling thru.

[
    {
        "url": "https://www.cdw.com",
        "technologies": [
            {
                "slug": "digicert",
                "name": "DigiCert",
                "versions": [],
                "trafficRank": 0,
                "confirmedAt": 1637573508,
                "categories": [
                    {
                        "id": 70,
                        "slug": "ssl-tls-certificate-authorities",
                        "name": "SSL/TLS certificate authorities"
                    }
                ]
            },
            {
                "slug": "hubspot",
                "name": "HubSpot",
                "versions": [],
                "trafficRank": 0,
                "confirmedAt": 1637573508,
                "categories": [
                    {
                        "id": 32,
                        "slug": "marketing-automation",
                        "name": "Marketing automation"
                    }
                ]
            },
            {
                "slug": "mailchimp",
                "name": "MailChimp",
                "versions": [],
                "trafficRank": 0,
                "confirmedAt": 1637573508,
                "categories": [
                    {
                        "id": 32,
                        "slug": "marketing-automation",
                        "name": "Marketing automation"
                    },
                    {
                        "id": 75,
                        "slug": "email",
                        "name": "Email"
                    }
                ]
            },
            {
                "slug": "apc",
                "name": "APC",
                "versions": [],
                "trafficRank": 380,
                "confirmedAt": 1637573508,
                "categories": [
                    {
                        "id": 99,
                        "slug": "shipping-carriers",
                        "name": "Shipping carriers"
                    }
                ]
            },

What is the quickest and most efficient way to extract the data from the nested array. I am using php and have tried foreach and for loops they aren't really working well.

  • Are you going to make a lot of queries? If yes, you should sort it and find the items in Log(n), but if you want to just find a couple of items, you should not sort it since it has a single time n.Log(n) overhead. – Amir MB Dec 11 '21 at 01:21
  • When you say extract the data, what do you mean? Do you just want something like `'url' => []`? Or are you looking for all technolgies that exist? Doing a foreach over the data and then accessing the `technologies` element would be the quickest way. – Jacob Mulquin Dec 11 '21 at 01:53
  • I am using this ```foreach($FieldData['technologies'] as $FieldDataItem){ echo $FieldDataItem['categories']['slug']; } – matthew parisi Dec 11 '21 at 03:17
  • if it helps this is where it is being used https://www.digitallyinsightful.com/main-view.php if you put in cdw.com as the domain name and click search it will return the above array the output i am parsing goes in the technologies section basically i am going to circle thru the array and populate the appropriate products in the categories. – matthew parisi Dec 11 '21 at 03:30

0 Answers0