Separar JSON

Enviada por Cézar Ayran 
Cézar Ayran
Separar JSON
10 de December de 2017 às 09:48AM
É uma pergunta boba rss mas já tentei várias syntax e nada. Abaixo tem o array onde eu o insiro na variável echo $workspace e eu consigo imprimir o ID dessa maneira $workspaces["lists"][0]["id"] mas eu quero por dentro do foreach pois pode ter mais de um resultado mas n consigo sempre dá erro tipo Notice: Undefined index: id com este código por exemplo:

foreach($workspaces as $value){
echo $value["id"];
}

Segue o array

Array
(
[lists] => Array
(
[0] => Array
(
[id] => 4a3497ddb7
[web_id] => 18757
[name] => The Experience Resorts
[contact] => Array
(
[company] => The Experience Resorts
[address1] => 23424 Park Hacienda
[address2] =>
[city] => Calabasas
[state] => CA
[zip] => 91302
[country] => US
[phone] =>
)

[permission_reminder] => You are receiving this email because you opted in via our website.
[use_archive_bar] => 1
[campaign_defaults] => Array
(
[from_name] => The Experience Resorts
[from_email] => info@theexperienceresorts.com
[subject] =>
[language] => en
)

[notify_on_subscribe] =>
[notify_on_unsubscribe] => info@theexperienceresorts.com
[date_created] => 2017-11-11T23:03:13+00:00
[list_rating] => 0
[email_type_option] =>
[subscribe_url_short] => http://eepurl.com/dbsbyT
[subscribe_url_long] => https://theexperienceresorts.us17.list-manage.com/subscribe?u=945caefbdb418f4eb4a3c580c&id=4a3497ddb7
[beamer_address] => us17-1abb011aab-558b16d386@inbound.mailchimp.com
[visibility] => pub
[modules] => Array
(
)

[stats] => Array
(
[member_count] => 17
[unsubscribe_count] => 0
[cleaned_count] => 1
[member_count_since_send] => 0
[unsubscribe_count_since_send] => 0
[cleaned_count_since_send] => 1
[campaign_count] => 2
[campaign_last_sent] => 2017-12-08T13:29:12+00:00
[merge_field_count] => 4
[avg_sub_rate] => 0
[avg_unsub_rate] => 0
[target_sub_rate] => 1
[open_rate] => 81.8181818182
[click_rate] => 0
[last_sub_date] => 2017-12-08T13:28:36+00:00
[last_unsub_date] =>
)

[_links] => Array
(
[0] => Array
(
[rel] => self
[href] => https://us17.api.mailchimp.com/3.0/lists/4a3497ddb7
[method] => GET
[targetSchema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/Response.json
)

[1] => Array
(
[rel] => parent
[href] => https://us17.api.mailchimp.com/3.0/lists
[method] => GET
[targetSchema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/CollectionResponse.json
[schema] => https://us17.api.mailchimp.com/schema/3.0/CollectionLinks/Lists.json
)

[2] => Array
(
[rel] => update
[href] => https://us17.api.mailchimp.com/3.0/lists/4a3497ddb7
[method] => PATCH
[targetSchema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/Response.json
[schema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/PATCH.json
)

[3] => Array
(
[rel] => batch-sub-unsub-members
[href] => https://us17.api.mailchimp.com/3.0/lists/4a3497ddb7
[method] => POST
[targetSchema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/BatchPOST-Response.json
[schema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/BatchPOST.json
)

[4] => Array
(
[rel] => delete
[href] => https://us17.api.mailchimp.com/3.0/lists/4a3497ddb7
[method] => DELETE
)

[5] => Array
(
[rel] => abuse-reports
[href] => https://us17.api.mailchimp.com/3.0/lists/4a3497ddb7/abuse-reports
[method] => GET
[targetSchema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/Abuse/CollectionResponse.json
[schema] => https://us17.api.mailchimp.com/schema/3.0/CollectionLinks/Lists/Abuse.json
)

[6] => Array
(
[rel] => activity
[href] => https://us17.api.mailchimp.com/3.0/lists/4a3497ddb7/activity
[method] => GET
[targetSchema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/Activity/Response.json
)

[7] => Array
(
[rel] => clients
[href] => https://us17.api.mailchimp.com/3.0/lists/4a3497ddb7/clients
[method] => GET
[targetSchema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/Clients/Response.json
)

[8] => Array
(
[rel] => growth-history
[href] => https://us17.api.mailchimp.com/3.0/lists/4a3497ddb7/growth-history
[method] => GET
[targetSchema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/Growth/CollectionResponse.json
[schema] => https://us17.api.mailchimp.com/schema/3.0/CollectionLinks/Lists/Growth.json
)

[9] => Array
(
[rel] => interest-categories
[href] => https://us17.api.mailchimp.com/3.0/lists/4a3497ddb7/interest-categories
[method] => GET
[targetSchema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/InterestCategories/CollectionResponse.json
[schema] => https://us17.api.mailchimp.com/schema/3.0/CollectionLinks/Lists/InterestCategories.json
)

[10] => Array
(
[rel] => members
[href] => https://us17.api.mailchimp.com/3.0/lists/4a3497ddb7/members
[method] => GET
[targetSchema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/CollectionResponse.json
[schema] => https://us17.api.mailchimp.com/schema/3.0/CollectionLinks/Lists/Members.json
)

[11] => Array
(
[rel] => merge-fields
[href] => https://us17.api.mailchimp.com/3.0/lists/4a3497ddb7/merge-fields
[method] => GET
[targetSchema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/MergeFields/CollectionResponse.json
[schema] => https://us17.api.mailchimp.com/schema/3.0/CollectionLinks/Lists/MergeFields.json
)

[12] => Array
(
[rel] => segments
[href] => https://us17.api.mailchimp.com/3.0/lists/4a3497ddb7/segments
[method] => GET
[targetSchema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/Segments/CollectionResponse.json
[schema] => https://us17.api.mailchimp.com/schema/3.0/CollectionLinks/Lists/Segments.json
)

[13] => Array
(
[rel] => webhooks
[href] => https://us17.api.mailchimp.com/3.0/lists/4a3497ddb7/webhooks
[method] => GET
[targetSchema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/Webhooks/CollectionResponse.json
[schema] => https://us17.api.mailchimp.com/schema/3.0/CollectionLinks/Lists/Webhooks.json
)

[14] => Array
(
[rel] => signup-forms
[href] => https://us17.api.mailchimp.com/3.0/lists/4a3497ddb7/signup-forms
[method] => GET
[targetSchema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/SignupForms/CollectionResponse.json
[schema] => https://us17.api.mailchimp.com/schema/3.0/CollectionLinks/Lists/SignupForms.json
)

[15] => Array
(
[rel] => locations
[href] => https://us17.api.mailchimp.com/3.0/lists/4a3497ddb7/locations
[method] => GET
[targetSchema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/Locations/CollectionResponse.json
[schema] => https://us17.api.mailchimp.com/schema/3.0/CollectionLinks/Lists/Locations.json
)

)

)

)

[total_items] => 1
[_links] => Array
(
[0] => Array
(
[rel] => self
[href] => https://us17.api.mailchimp.com/3.0/lists
[method] => GET
[targetSchema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/CollectionResponse.json
[schema] => https://us17.api.mailchimp.com/schema/3.0/CollectionLinks/Lists.json
)

[1] => Array
(
[rel] => parent
[href] => https://us17.api.mailchimp.com/3.0/
[method] => GET
[targetSchema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Root/Response.json
)

[2] => Array
(
[rel] => create
[href] => https://us17.api.mailchimp.com/3.0/lists
[method] => POST
[targetSchema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/Response.json
[schema] => https://us17.api.mailchimp.com/schema/3.0/Definitions/Lists/POST.json
)

)

)
Cézar Ayran
Re: Separar JSON
10 de December de 2017 às 11:31AM
PS: Eu consigo obter os dados com for(){} mas gostaria de utilizar foreach(){}
Trambulhao
Re: Separar JSON
11 de December de 2017 às 12:04PM
Não será isso?

foreach ($workspaces as $value) {
echo $value[0]['id'], '<br>';
}
Você precisa estar logado no PHPBrasil.com para poder enviar mensagens para os nossos fóruns.

Faça o login aqui.