0

I am doing this to get data back from an API and I need to loop through it to gain access to the [value]

code

$url='MYAPIURL';
$result = file_get_contents($url);
$resultData = json_decode($result, true);

echo "<pre>";
print_r($resultData);

And I'm getting:

code

Array
(
    [results] => Array
        (
            [0] => Array
                (
                    [submittedAt] => 1614006543396
                    [values] => Array
                        (
                            [0] => Array
                                (
                                    [name] => firstname
                                    [value] => Michael
                                    [objectTypeId] => 0-1
                                )
                        [1] => Array
                            (
                                [name] => lastname
                                [value] => Smith
                                [objectTypeId] => 0-1
                            )

                        [2] => Array
                            (
                                [name] => email
                                [value] => msmith@doveprintsolutions.com
                                [objectTypeId] => 0-1
                            )

                        [3] => Array
                            (
                                [name] => phone
                                [value] => 9192101657
                                [objectTypeId] => 0-1
                            )

                        [4] => Array
                            (
                                [name] => company
                                [value] => Dove Print Solutions
                                [objectTypeId] => 0-1
                            )

                        [5] => Array
                            (
                                [name] => country_select
                                [value] => United States
                                [objectTypeId] => 0-1
                            )

                        [6] => Array
                            (
                                [name] => en_gdpr_consent
                                [value] => true
                                [objectTypeId] => 0-1
                            )

                        [7] => Array
                            (
                                [name] => contact_digital_process_expert_
                                [value] => false
                                [objectTypeId] => 0-1
                            )

                        [8] => Array
                            (
                                [name] => utm_medium
                                [value] => email
                                [objectTypeId] => 0-1
                            )

                        [9] => Array
                            (
                                [name] => utm_campaign
                                [value] => UserInfo
                                [objectTypeId] => 0-1
                            )

                        [10] => Array
                            (
                                [name] => utm_source
                                [value] => hs_email
                                [objectTypeId] => 0-1
                            )

                    )

                
            )

        [1] => Array
            (
                [submittedAt] => 1612273662300
                [values] => Array
                    (
                        [0] => Array
                            (
                                [name] => firstname
                                [value] => David
                                [objectTypeId] => 0-1
                            )

                        [1] => Array
                            (
                                [name] => lastname
                                [value] => Bürscher
                                [objectTypeId] => 0-1
                            )

                        [2] => Array
                            (
                                [name] => email
                                [value] => david.buerscher@softsolution.at
                                [objectTypeId] => 0-1
                            )

                        [3] => Array
                            (
                                [name] => phone
                                [value] => +43722420034506
                                [objectTypeId] => 0-1
                            )

                        [4] => Array
                            (
                                [name] => company
                                [value] => Softsolution GmbH
                                [objectTypeId] => 0-1
                            )

                        [5] => Array
                            (
                                [name] => country_select
                                [value] => Austria
                                [objectTypeId] => 0-1
                            )

                        [6] => Array
                            (
                                [name] => en_gdpr_consent
                                [value] => true
                                [objectTypeId] => 0-1
                            )

                        [7] => Array
                            (
                                [name] => contact_digital_process_expert_
                                [value] => false
                                [objectTypeId] => 0-1
                            )

                    )

               

      

How can I parse the arrays and get the [value] as separate variables like firstname lastname etc? I have tried a number of different ways but have failed. Can someone please help me out?

RiggsFolly
  • 89,708
  • 20
  • 100
  • 143
  • can you please try `print("
    ".print_r($result,true)."
    ");` to see the structure more detailed
    – Ruben Aug 31 '21 at 16:48

0 Answers0