如何从对象stdclass中获取值并将它们放在不同的数组中?

时间:2016-06-12 12:21:34

标签: php arrays json

Array
(
    [0] => stdClass Object
        (
            [id] => 61c2e3b8-0493-415c-950d-01216408080b
            [idStatus] => 
            [isUser] => 
            [company] => 
            [department] => 
            [companyID] => 
            [contactType] => Contact
            [firstName] => Raman
            [lastName] => 
            [middleName] => 
            [nameSuffix] => 
            [namePrefix] => 
            [fullName] => 
            [referredBy] => 
            [salutation] => 
            [jobTitle] => hello
            [emailAddress] => 
            [altEmailAddress] => 
            [personalEmailAddress] => 
            [businessPhone] => 
            [businessExtension] => 
            [mobilePhone] => 
            [mobileExtension] => 
            [homePhone] => 
            [homeExtension] => 
            [website] => 
            [birthday] => 
            [businessAddress] => stdClass Object
                (
                    [line1] => sector 8
                    [line2] => Madhya Marg
                    [line3] => 
                    [city] => 
                    [state] => 
                    [postalCode] => 
                    [country] => 
                )

            [homeAddress] => stdClass Object
                (
                    [line1] => 
                    [line2] => 
                    [line3] => 
                    [city] => 
                    [state] => 
                    [postalCode] => 
                    [country] => 
                )

            [pagerPhone] => 
            [pagerExtension] => 
            [faxPhone] => 
            [faxExtension] => 
            [alternatePhone] => 
            [alternateExtension] => 
            [customFields] => stdClass Object
                (
                    [spouse] => 
                    [amount a] => 
                    [client category] => 
                    [amount 5a] => 
                    [contact 2 smoker status] => 
                    [type of policy 3] => 
                    [contact 2_state] => 
                    [user10] => 
                    [contact 2_address_1] => 
                    [address 1 for replace] => 
                    [contact 2 mobile_extension] => 
                    [city for replace] => 
                    [contact 2_city] => 
                    [charity] => 
                    [phone1_extension] => 
                    [policy start date 1] => 
                    [premium 1] => 
                    [spouse preferred name] => 
                    [contact 2 gender] => 
                    [smoker] => False
                    [contact 2_zip_code] => 
                    [contact 2 home_extension] => 
                    [adviser] => 
                    [amount 6c] => 
                    [user6] => 
                    [user5] => 
                    [policy number 6] => 
                    [user3] => 
                    [type of policy 4] => 
                    [user4] => 
                    [product manufacturer 2] => 
                    [contact 2 preferred contact method] => 
                    [contact 2_address_2] => 
                    [contact 2 dob] => 
                    [user8] => 
                    [preferred contact method] => 
                    [phone2_extension] => 
                    [policy start date 5] => 
                    [amount 5c] => 
                    [policy start date 3] => 
                    [type of policy 2] => 
                    [service package] => 
                    [policy number 3] => 
                    [product manufacturer 3] => 
                    [policy start date 4] => 
                    [policy number 1] => 
                    [amount 5b] => 
                    [premium 3] => 
                    [amount 7c] => 
                    [policy number 4] => 
                    [review month] => 
                    [phone2_phone] => 
                    [user9] => 
                    [contact 2 work_extension] => 
                    [marital status] => 
                    [amount 7b] => 
                    [type of policy 7] => 
                    [contact 2 mobile_phone] => 
                    [amount 7a] => 
                    [policy number 2] => 
                    [preferred name] => 
                    [gender] => 
                    [user7] => 
                    [contact 2 work_phone] => 
                    [amount 6b] => 
                    [amount 1c] => 
                    [contact 2_country] => 
                    [phone1_phone] => 
                    [policy start date 2] => 
                    [amount b] => 
                    [smoker status] => 
                    [policy number 7] => 
                    [amount 6a] => 
                    [policy start date 6] => 
                    [policy number 5] => 
                    [type of policy] => 
                    [policy start date 7] => 
                    [amount 4c] => 
                    [premium 2] => 
                    [amount 4b] => 
                    [product manufacturer] => 
                    [premium 5] => 
                    [type of policy 6] => 
                    [contact 2_address_3] => 
                    [contact 2 home_phone] => 
                    [type of policy 5] => 
                    [contact 2 alternate email_e-mail] => 
                    [premium 4] => 
                    [contact 2 e-mail_e-mail] => 
                    [stepped or level 6] => 
                    [dependant relation] => 
                    [all in order 4] => False
                    [product manufacturer 5] => 
                    [amount 3a] => 
                    [product category 6] => 
                    [exclusion & loading] => 
                    [docs folder] => 
                    [stepped or level] => 
                    [date] => 
                    [alternate e-mail 2] => 
                    [product manufacturer 4a] => 
                    [product category 4a] => 
                    [premium 4a] => 
                    [date updated] => 
                    [dependant 1] => 
                    [dependant dob] => 
                    [wedding date] => 
                    [contact 2 employer] => 
                    [type of policy 8] => 
                    [review issue] => 
                    [product category 7] => 
                    [product category 3] => 
                    [revenue] => 
                    [dependant 3 dob] => 
                    [contact 2 title] => 
                    [contact 2 occupation] => 
                    [dependant 2 gender] => 
                    [amount 9a] => 
                    [policy start date 9] => 
                    [amount 9c] => 
                    [policy start date 8] => 
                    [product manufacturer 8] => 
                    [date submitted to ins co] => 
                    [product category 1] => 
                    [stepped or level 5] => 
                    [amount 8b] => 
                    [amount 2c] => 
                    [amount 9b] => 
                    [premium 7] => 
                    [product category 4] => 
                    [premium structure & commission type 8] => 
                    [accountant] => 
                    [dependant 3 gender] => 
                    [amount 3b] => 
                    [amount 3c] => 
                    [dependant 3 relation] => 
                    [amount 8c] => 
                    [all in order 1] => False
                    [product manufacturer 7] => 
                    [relationship] => 
                    [acc_name] => 
                    [type of policy 9] => 
                    [product category 8] => 
                    [product category 2] => 
                    [product manufacturer 4] => 
                    [dependant 3] => 
                    [dependant 2 dob] => 
                    [existing_policy] => 
                    [cur_insurer] => 
                    [amount 2b] => 
                    [all in order 2] => False
                    [product manufacturer 6] => 
                    [all in order 3] => False
                    [policy number 8] => 
                    [partner title] => 
                    [amount 8a] => 
                    [stepped or level 3] => 
                    [stepped or level 7] => 
                    [product category 5] => 
                    [occupation] => 
                    [premium 8] => 
                    [amount 2a] => 
                    [url] => 
                    [dependant 2] => 
                    [dependant gender] => 
                    [stepped or level 4] => 
                    [comment] => 
                    [policy number 9] => 
                    [dependant 2 relation] => 
                    [dob] => 
                    [amount 4a] => 
                    [stepped or level 2] => 
                    [premium structure & commission type 4a] => 
                    [date recd signed soa] => 
                    [premium 6] => 
                    [replacement insurer] => 
                    [replacement life insured] => 
                    [account name 3] => 
                    [banked nb 3] => 
                    [existing policy] => 
                    [replacement sum insured proposed] => 
                    [account name 41] => 
                    [date of commission statement 4] => 
                    [hybrid or upfront] => 
                    [replacement date of commencement proposed] => 
                    [areas of interest 5] => 
                    [rec monthly benefit waiting period 2] => 
                    [hybrid or upfront 4] => 

                )


        )

    [1] => stdClass Object
        (
            [id] => 364eb648-817a-427a-af64-0776e873b780
            [idStatus] => 
            [isUser] => 
            [company] => 
            [department] => 
            [companyID] => 
            [contactType] => Contact
            [firstName] => gourav
            [lastName] => turan
            [middleName] => 
            [nameSuffix] => 
            [namePrefix] => 
            [fullName] => gourav turan
            [referredBy] => 
            [salutation] => gourav
            [jobTitle] => hi
            [emailAddress] => 
            [altEmailAddress] => 
            [personalEmailAddress] => 
            [businessPhone] => 
            [businessExtension] => 
            [mobilePhone] => 
            [mobileExtension] => 
            [homePhone] => 
            [homeExtension] => 
            [website] => 
            [birthday] => 
            [businessAddress] => stdClass Object
                (
                    [line1] => 
                    [line2] => 
                    [line3] => 
                    [city] => 
                    [state] => 
                    [postalCode] => 
                    [country] => 
                )

            [homeAddress] => stdClass Object
                (
                    [line1] => 
                    [line2] => 
                    [line3] => 
                    [city] => 
                    [state] => 
                    [postalCode] => 
                    [country] => 
                )

            [pagerPhone] => 
            [pagerExtension] => 
            [faxPhone] => 
            [faxExtension] => 
            [alternatePhone] => 
            [alternateExtension] => 
            [customFields] => stdClass Object
                (
                    [spouse] => 
                    [amount a] => 
                    [client category] => 
                    [amount 5a] => 
                    [contact 2 smoker status] => 
                    [type of policy 3] => 
                    [contact 2_state] => 
                    [user10] => 
                    [contact 2_address_1] => 
                    [address 1 for replace] => 
                    [contact 2 mobile_extension] => 
                    [city for replace] => 
                    [contact 2_city] => 
                    [charity] => 
                    [phone1_extension] => 
                    [policy start date 1] => 
                    [premium 1] => 
                    [spouse preferred name] => 
                    [contact 2 gender] => 
                    [smoker] => False
                    [contact 2_zip_code] => 
                    [contact 2 home_extension] => 
                    [adviser] => 
                    [amount 6c] => 
                    [user6] => 
                    [user5] => 
                    [policy number 6] => 
                    [user3] => 
                    [type of policy 4] => 
                    [user4] => 
                    [product manufacturer 2] => 
                    [contact 2 preferred contact method] => 
                    [contact 2_address_2] => 
                    [contact 2 dob] => 
                    [user8] => 
                    [preferred contact method] => 
                    [phone2_extension] => 
                    [policy start date 5] => 
                    [amount 5c] => 
                    [policy start date 3] => 
                    [type of policy 2] => 
                    [service package] => 
                    [policy number 3] => 
                    [product manufacturer 3] => 
                    [policy start date 4] => 
                    [policy number 1] => 
                    [amount 5b] => 
                    [premium 3] => 
                    [amount 7c] => 
                    [policy number 4] => 
                    [review month] => 
                    [phone2_phone] => 
                    [user9] => 
                    [contact 2 work_extension] => 
                    [marital status] => 
                    [amount 7b] => 
                    [type of policy 7] => 
                    [contact 2 mobile_phone] => 
                    [amount 7a] => 
                    [policy number 2] => 
                    [preferred name] => 
                    [gender] => 
                    [user7] => 
                    [contact 2 work_phone] => 
                    [amount 6b] => 
                    [amount 1c] => 
                    [contact 2_country] => 
                    [phone1_phone] => 
                    [policy start date 2] => 
                    [amount b] => 
                    [smoker status] => 
                    [policy number 7] => 
                    [amount 6a] => 
                    [policy start date 6] => 
                    [policy number 5] => 
                    [type of policy] => 
                    [policy start date 7] => 
                    [amount 4c] => 
                    [premium 2] => 
                    [amount 4b] => 
                    [product manufacturer] => 
                    [premium 5] => 
                    [type of policy 6] => 
                    [contact 2_address_3] => 
                    [contact 2 home_phone] => 
                    [type of policy 5] => 
                    [contact 2 alternate email_e-mail] => 
                    [premium 4] => 
                    [contact 2 e-mail_e-mail] => 
                    [stepped or level 6] => 
                    [dependant relation] => 
                    [all in order 4] => False
                    [product manufacturer 5] => 
                    [amount 3a] => 
                    [product category 6] => 
                    [exclusion & loading] => 
                    [docs folder] => 
                    [stepped or level] => 
                    [date] => 
                    [alternate e-mail 2] => 
                    [product manufacturer 4a] => 
                    [product category 4a] => 
                    [premium 4a] => 
                    [date updated] => 
                    [dependant 1] => 
                    [dependant dob] => 
                    [wedding date] => 
                    [contact 2 employer] => 
                    [type of policy 8] => 
                    [review issue] => 
                    [product category 7] => 
                    [product category 3] => 
                    [revenue] => 
                    [dependant 3 dob] => 
                    [contact 2 title] => 
                    [contact 2 occupation] => 
                    [dependant 2 gender] => 
                    [amount 9a] => 
                    [policy start date 9] => 
                    [amount 9c] => 
                    [policy start date 8] => 
                    [product manufacturer 8] => 
                    [date submitted to ins co] => 
                    [product category 1] => 
                    [stepped or level 5] => 
                    [amount 8b] => 
                    [amount 2c] => 
                    [amount 9b] => 
                    [premium 7] => 
                    [product category 4] => 
                    [premium structure & commission type 8] => 
                    [accountant] => 
                    [dependant 3 gender] => 
                    [amount 3b] => 
                    [amount 3c] => 
                    [dependant 3 relation] => 
                    [amount 8c] => 
                    [all in order 1] => False
                    [product manufacturer 7] => 
                    [relationship] => 
                    [acc_name] => 
                    [type of policy 9] => 
                    [product category 8] => 
                    [product category 2] => 
                    [product manufacturer 4] => 
                    [dependant 3] => 
                    [dependant 2 dob] => 
                    [existing_policy] => 
                    [cur_insurer] => 
                    [amount 2b] => 
                    [all in order 2] => False
                    [product manufacturer 6] => 
                    [all in order 3] => False
                    [policy number 8] => 
                    [partner title] => 
                    [amount 8a] => 
                    [stepped or level 3] => 
                    [stepped or level 7] => 
                    [product category 5] => 
                    [occupation] => 
                    [premium 8] => 
                    [amount 2a] => 
                    [url] => 
                    [dependant 2] => 
                    [dependant gender] => 
                    [stepped or level 4] => 
                    [comment] => 
                    [policy number 9] => 
                    [dependant 2 relation] => 
                    [dob] => 
                    [amount 4a] => 
                    [stepped or level 2] => 
                    [premium structure & commission type 4a] => 
                    [date recd signed soa] => 
                    [premium 6] => 
                    [replacement insurer] => 
                    [replacement life insured] => 
                    [account name 3] => 
                    [banked nb 3] => 
                    [existing policy] => 
                    [replacement sum insured proposed] => 
                    [account name 41] => 
                    [date of commission statement 4] => 
                    [hybrid or upfront] => 
                    [replacement date of commencement proposed] => 
                    [areas of interest 5] => 
                    [rec monthly benefit waiting period 2] => 
                    [hybrid or upfront 4] => 
                    [builderphone] => 
                    [banked nb] => 
                    [rec monthly benefit insurer and type 2] => 
                    [agent] => 
                    [expected nb 2] => 
                    [rec lump sum sum optional extras] => 
                    [rec monthly benefit waiting period] => 
                    [replacement date of commencement] => 
                    [banked nb 4] => 
                    [insurance type 1] => 
                    [current insurer 3] => 
                    [current insurer 4] => 
                    [rec monthly benefit sum insured 2] => 
                    [rec monthly benefit benefit period 2] => 
                    [current insurer 41] => 
                    [replacement premium and payment frequency proposed] => 
                    [account name 2] => 
                    [rec monthly benefit premium type] => 
                    [rec monthly benefit benefit period] => 
                    [current insurer 31] => 
                    [account name 31] => 
                    [replacement insurer proposed] => 
                    [expected nb 3] => 
                    [rec lump sum insurer and type 2] => 
                    [rec lump sum sum insured 2] => 
                    [gp percentage] => 
                    [hybrid or upfront 2] => 
                    [rec monthly benefit premium 2] => 
                    [current insurer 1] => 
                    [insurance type 4] => 
                    [ip address] => 
                    [health] => 
                    [areas of interest 4] => 
                    [rec lump sum premium 2] => 
                    [areas of interest 3] => 
                    [areas of interest 2] => 
                    [builder phone] => 
                    [banked nb 2] => 
                    [account name 4] => 
                    [rec monthly benefit sum insured] => 
                    [rec monthly benefit premium ] => 
                    [rec lump sum premium type 2] => 
                    [financial inst] => 
                    [replacement life insured proposed] => 
                    [expected nb 4] => 
                    [date of commission statement 3] => 
                    [time stamp] => 
                    [replacement type of product] => 
                    [areas of interest 1] => 
                    [rec lump sum insurer and type] => 
                    [date of commission statement] => 
                    [rec lump sum premium type] => 
                    [status] => 
                    [account name 1] => 
                    [current insurer 2] => 
                    [retain or replace] => 
                    [policy number] => 
                    [date of commission statement 2] => 
                    [replacement sum insured] => 
                    [primary goals and objectives] => 
                    [replaced fi policy no] => 
                    [rec lump sum sum insured] => 
                    [insurance type  2] => 
                    [comments] => 
                    [replacement policy no proposed] => 
                    [account name 21] => 
                    [expected nb] => 
                    [rec monthly benefit insurer and type] => 
                    [replacement premium and payment frequency] => 
                    [do not contact] => 
                    [scope of advice] => 
                    [replacement policy no] => 
                    [docs back] => 
                    [policy_number] => 
                    [current insurer 21] => 
                    [insurance type 3] => 
                    [date policy start] => 
                    [hybrid or upfront 3] => 
                    [rec lump sum sum optional extras 2] => 
                    [life insured] => 
                    [replacement type of product proposed] => 
                    [omnium] => 
                    [results of our recomendation] => 
                    [rec lump sum sum premium] => 
                    [docs out] => 
                )


        )

这就是我所做的......但我没有取得丰硕成果

<?php
$hello= json_decode($json);
echo"<pre>";
  print_r($hello);
?>

我必须抓取“id&#39;和&#39; businessAdress [&#39; line1&#39;]&#39;所有客户端并将它们放在不同的数组中。

1 个答案:

答案 0 :(得分:0)

你可以获取“id”#39;和&#39; businessAdress [&#39; line1&#39;]&#39;这样:

<?php
foreach($hello as $object)
{
    echo 'id: ' . $object->id;
    echo 'business address: ' . $object->businessAdress->line1;
}