如何在PHP中循环JSON对象值?

时间:2016-09-26 11:51:03

标签: php arrays json loops

我有一个JSON对象,我想循环遍历值:

$json = '{"1":a,"2":b,"3":c,"4":d,"5":e}';
$obj = json_decode($json, TRUE);
for($i=0; $i<count($obj['a']); $i++) {
    echo $i;
}

我希望$i显示作为对象中值的abcde

2 个答案:

答案 0 :(得分:12)

尝试使用。

C:\....>git init
Initialized empty Git repository in C:/..../.git/

C:\....>git remote add origin \\\\10.30.1.15\\GitRepositories\\MyApp

C:\....>git add .

C:\....>git commit -m 'intial'
[master (root-commit) 6870ea2] 'intial'
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test.txt

C:\....>git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 207 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To \\\\10.30.1.15\\\\GitRepositories\\MyApp
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '\\\\10.30.1.15\\GitRepositories\\MyApp'

p.s未经测试; - )

答案 1 :(得分:7)

迭代它的最短方式,这种你不关心索引的方式是使用foreach($obj as $value) { echo $value; } 这样:

$obj

例如,您的Range("Q" & y & ":T" & y).Merge 中没有索引0。从我看来它从1开始。这样它就可以处理任何索引(不仅仅是数字)