Php 使用forlopp打印阵列数据 $responses=stdClass对象( [状态]=>成功 [值]=>stdClass对象( [messageTaskList]=>数组( [0]=>stdClass对象( [id]=>19 [userId]=>38 [文本]=>一些文本 [currentCount]=>0 [finishCount]=>5000 [createTime]=>1470223038000 [完成时间]=> [状态]=>1 [requestsSent]=>0 [url]=>linked.in/searchparams=marketingits=sample) [1] =>stdClass对象( [id]=>20 [userId]=>38 [文本]=>大急流 [currentCount]=>0 [finishCount]=>5000 [createTime]=>1470223059000 [完成时间]=> [状态]=>1 [requestsSent]=>0 [url]=>linked.in/searchparams=marketingits=sample) [2] =>stdClass对象( [id]=>21 [userId]=>38 [文本]=>大急流 [currentCount]=>0 [finishCount]=>5000 [createTime]=>1470223751000 [完成时间]=> [状态]=>1 [requestsSent]=>0 [网址]=>https://google.com ) ) ) [操作]=>获取消息任务列表 [eventId]=>) foreach($key=>$value){ 回显$value->id.,“$value->text.””; }
我试图在表中显示数组值,但得到了下面提到的错误 注意:尝试获取E:\xampp\htdocs\linkedin\all-tasks.php中非对象的属性,第238行 注意:尝试获取E:\xampp\htdocs\linkedin\all-tasks.php中非对象的属性,第238行Php 使用forlopp打印阵列数据 $responses=stdClass对象( [状态]=>成功 [值]=>stdClass对象( [messageTaskList]=>数组( [0]=>stdClass对象( [id]=>19 [userId]=>38 [文本]=>一些文本 [currentCount]=>0 [finishCount]=>5000 [createTime]=>1470223038000 [完成时间]=> [状态]=>1 [requestsSent]=>0 [url]=>linked.in/searchparams=marketingits=sample) [1] =>stdClass对象( [id]=>20 [userId]=>38 [文本]=>大急流 [currentCount]=>0 [finishCount]=>5000 [createTime]=>1470223059000 [完成时间]=> [状态]=>1 [requestsSent]=>0 [url]=>linked.in/searchparams=marketingits=sample) [2] =>stdClass对象( [id]=>21 [userId]=>38 [文本]=>大急流 [currentCount]=>0 [finishCount]=>5000 [createTime]=>1470223751000 [完成时间]=> [状态]=>1 [requestsSent]=>0 [网址]=>https://google.com ) ) ) [操作]=>获取消息任务列表 [eventId]=>) foreach($key=>$value){ 回显$value->id.,“$value->text.””; },php,arrays,Php,Arrays,我试图在表中显示数组值,但得到了下面提到的错误 注意:尝试获取E:\xampp\htdocs\linkedin\all-tasks.php中非对象的属性,第238行 注意:尝试获取E:\xampp\htdocs\linkedin\all-tasks.php中非对象的属性,第238行 id和text位于value和messageTaskList的数组对象中,因此通过在其上放置指针,循环进入id和text所在的内部数组 这将有助于: $responses= stdClass Object ( [s
id
和text
位于value
和messageTaskList
的数组对象中,因此通过在其上放置指针,循环进入id
和text
所在的内部数组
这将有助于:
$responses= stdClass Object (
[status] => SUCCESS
[value] => stdClass Object (
[messageTaskList] => Array (
[0] => stdClass Object (
[id] => 19
[userId] => 38
[text] => some text
[currentCount] => 0
[finishCount] => 5000
[createTime] => 1470223038000
[finishTime] =>
[status] => 1
[requestsSent] => 0
[url] => linked.in/searchparams=marketingits=sample )
[1] => stdClass Object (
[id] => 20
[userId] => 38
[text] => Grand Rapids
[currentCount] => 0
[finishCount] => 5000
[createTime] => 1470223059000
[finishTime] =>
[status] => 1
[requestsSent] => 0
[url] => linked.in/searchparams=marketingits=sample )
[2] => stdClass Object (
[id] => 21
[userId] => 38
[text] => Grand Rapids
[currentCount] => 0
[finishCount] => 5000
[createTime] => 1470223751000
[finishTime] =>
[status] => 1
[requestsSent] => 0
[url] => https://google.com ) ) )
[action] => GET_MESSAGE_TASK_LIST
[eventId] => )
foreach($responses as $key => $value) {
echo $value->id . ", " . $value->text . "<br>";
}
foreach($responses->value->messagetasklistas$key=>value){
回显$value->id.,“$value->text.”
”;
}
id
和text
在value
和messageTaskList
的数组对象中,因此通过将指针放在同一数组上,循环进入id
和text
所在的内部数组
这将有助于:
$responses= stdClass Object (
[status] => SUCCESS
[value] => stdClass Object (
[messageTaskList] => Array (
[0] => stdClass Object (
[id] => 19
[userId] => 38
[text] => some text
[currentCount] => 0
[finishCount] => 5000
[createTime] => 1470223038000
[finishTime] =>
[status] => 1
[requestsSent] => 0
[url] => linked.in/searchparams=marketingits=sample )
[1] => stdClass Object (
[id] => 20
[userId] => 38
[text] => Grand Rapids
[currentCount] => 0
[finishCount] => 5000
[createTime] => 1470223059000
[finishTime] =>
[status] => 1
[requestsSent] => 0
[url] => linked.in/searchparams=marketingits=sample )
[2] => stdClass Object (
[id] => 21
[userId] => 38
[text] => Grand Rapids
[currentCount] => 0
[finishCount] => 5000
[createTime] => 1470223751000
[finishTime] =>
[status] => 1
[requestsSent] => 0
[url] => https://google.com ) ) )
[action] => GET_MESSAGE_TASK_LIST
[eventId] => )
foreach($responses as $key => $value) {
echo $value->id . ", " . $value->text . "<br>";
}
foreach($responses->value->messagetasklistas$key=>value){
回显$value->id.,“$value->text.”
”;
}
您的$responses结构就是这样的:
foreach($responses->value->messageTaskList as $key => $value) {
echo $value->id . ", " . $value->text . "<br>";
}
您需要做的就是迭代正确的元素:
$responses = stdClass (
[status] => SUCCESS
[value] =>
stdClass Object (
[messageTaskList] => Array (
[0] => stdClass Object (
[id] => 19
[userId] => 38
[text] => some text
[currentCount] => 0
[finishCount] => 5000
[createTime] => 1470223038000
[finishTime] =>
[status] => 1
[requestsSent] => 0
[url] => linked.in/searchparams=marketingits=sample
)
[1] => stdClass Object (
[id] => 20
[userId] => 38
[text] => Grand Rapids
[currentCount] => 0
[finishCount] => 5000
[createTime] => 1470223059000
[finishTime] =>
[status] => 1
[requestsSent] => 0
[url] => linked.in/searchparams=marketingits=sample
)
[2] => stdClass Object (
[id] => 21
[userId] => 38
[text] => Grand Rapids
[currentCount] => 0
[finishCount] => 5000
[createTime] => 1470223751000
[finishTime] =>
[status] => 1
[requestsSent] => 0
[url] => https://google.com
)
)
)
[action] => GET_MESSAGE_TASK_LIST
[eventId] =>
)
foreach($responses->value->messagetasklistas$key=>value){
回显$value->id.,“$value->text.”
”;
}
您的$responses结构就是这样的:
foreach($responses->value->messageTaskList as $key => $value) {
echo $value->id . ", " . $value->text . "<br>";
}
您需要做的就是迭代正确的元素:
$responses = stdClass (
[status] => SUCCESS
[value] =>
stdClass Object (
[messageTaskList] => Array (
[0] => stdClass Object (
[id] => 19
[userId] => 38
[text] => some text
[currentCount] => 0
[finishCount] => 5000
[createTime] => 1470223038000
[finishTime] =>
[status] => 1
[requestsSent] => 0
[url] => linked.in/searchparams=marketingits=sample
)
[1] => stdClass Object (
[id] => 20
[userId] => 38
[text] => Grand Rapids
[currentCount] => 0
[finishCount] => 5000
[createTime] => 1470223059000
[finishTime] =>
[status] => 1
[requestsSent] => 0
[url] => linked.in/searchparams=marketingits=sample
)
[2] => stdClass Object (
[id] => 21
[userId] => 38
[text] => Grand Rapids
[currentCount] => 0
[finishCount] => 5000
[createTime] => 1470223751000
[finishTime] =>
[status] => 1
[requestsSent] => 0
[url] => https://google.com
)
)
)
[action] => GET_MESSAGE_TASK_LIST
[eventId] =>
)
foreach($responses->value->messagetasklistas$key=>value){
回显$value->id.,“$value->text.”
”;
}
OP为什么要“使用此代码”?一个好的答案总是会有一个解释,说明做了什么以及为什么这样做,不仅是为了OP,而且是为了未来的访问者,以便他们能够找到这个问题并阅读您的答案。“id”和“text”在“value”和“messageTaskList”的数组对象中,因此通过在同一个数组对象上放置指针,循环进入“id”和“text”所在的内部数组。我明白了。。谢谢你的帮助太好了,我在你的回答中补充了这一点,你应该把它放在那里。所以现在绝对值得投一票,所以我给了你一票。好的答案会让你获得选票(+10)和被接受的答案(+15)为什么OP“使用此代码”?一个好的答案总是会有一个解释,说明做了什么以及为什么这样做,不仅是为了OP,而且是为了未来的访问者,以便他们能够找到这个问题并阅读您的答案。“id”和“text”在“value”和“messageTaskList”的数组对象中,因此通过在同一个数组对象上放置指针,循环进入“id”和“text”所在的内部数组。我明白了。。谢谢你的帮助太好了,我在你的回答中补充了这一点,你应该把它放在那里。所以现在绝对值得投一票,所以我给了你一票。好的答案会让你获得选票(+10)和被接受的答案(+15)