オブジェクト内にいくつの値があるかを調べるために反復しようとしているJSONオブジェクトがあります。PHPのcount()は常に1を返します
My JSON;
[{
"accountId": "1746756959",
"containerId": "7454209",
"containerVersionId": "7",
"container": {
"accountId": "1746756959",
"containerId": "7454209"
},
"tag": [{
"accountId": "1746756959",
"name": "Universal Analytics",
"parameter": [{
"key": "overrideGaSettings",
"type": "boolean",
"value": "false"
}]
}, {
"accountId": "1746756959",
"parameter": [{
"key": "detectTitle",
"type": "boolean",
"value": "true"
}]
}, {
"accountId": "1746756959",
"name": "contentEngagement",
"parameter": [{
"key": "html",
"type": "template",
"value": "<script>\n\n<\/script>"
}]
}],
"trigger": [{
"accountId": "1746756959",
"name": "Trigger 1",
"workspaceId": null
}, {
"accountId": "1746756959",
"name": "Trigger 2",
"workspaceId": null
}, {
"accountId": "1746756959",
"containerId": "7454209",
"fingerprint": "1507893475158",
"name": "Trigger 3",
"notes": null,
"parentFolderId": null,
"path": null,
"tagManagerUrl": null,
"triggerId": "13",
"type": "windowLoaded",
"workspaceId": null
}],
"variable": [{
"accountId": "1746756959",
"containerId": "7454209",
"disablingTriggerId": null,
"enablingTriggerId": null,
"fingerprint": "1505216399119",
"name": "Google Analytics Settings",
"notes": null,
"parentFolderId": null,
"path": null,
"scheduleEndMs": null,
"scheduleStartMs": null,
"tagManagerUrl": null,
"type": "gas",
"variableId": "1",
"workspaceId": null,
"parameter": [{
"key": "cookieDomain",
"type": "template",
"value": "auto"
}]
}]
}]
私はそれを行うことができます値を反復処理し、プリントアウトしてみてください、私はそれを数えるとき、私は(3)
があるべきとき(1 1 1)
ような結果を得ます。私はそれがforeachと関係があると思う。私のPHPコードは次のようになります。
foreach($LiveContainer as $item) {
foreach ($item['tag'] as $accountPath) {
echo count($accountPath->name); echo "<br>";
}}
結果:
私が欲しいものはtag
にありますどのように多くの項目数えることです。
PS:その非常に長い、maby "名前" は、すべてのタグにその
感謝のために残念利用できないので、私はJSONからたくさん削除が
数 'と間違って何($ item ['tag']) '? – raina77ow