首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在PHP foreach语句中从JSON数组获取数据

在PHP foreach语句中从JSON数组获取数据
EN

Stack Overflow用户
提问于 2018-06-09 01:36:41
回答 2查看 60关注 0票数 0

我正在尝试从JSON数组中获取数据-该数组的结构非常复杂。

这是我的数组:

Array
(
[query] => Plagiarism is the "wrongful appropriation" and "stealing and publication"
[data] => Array
    (
        [error] => 0
        [webs] => Array
            (
                [0] => Array
                    (
                        [title] => Plagiarism - Wikipedia
                        [url] => https://en.wikipedia.org/wiki/Plagiarism
                        [des] => 
                    )

                [1] => Array
                    (
                        [title] => Plagiarism - Wikipedia
                        [url] => https://en.wikipedia.org/wiki/Plagiarism
                        [des] => Plagiarism is the "wrongful appropriation" and "stealing and publication" of another author's "language, thoughts, ideas, or expressions" and the representation of them as one's own original work. Plagiarism is considered academic dishonesty and a breach of journalistic ethics.
                    )

                [2] => Array
                    (
                        [title] => What is the concept of plagiarism? - ResearchGate
                        [url] => https://www.researchgate.net/post/What_is_the_concept_of_plagiarism
                        [des] => “Plagiarism is the "wrongful appropriation" and "stealing and publication" of another author's "language, thoughts, ideas, or expressions" and the representation of them as one's own original work.
                    )

                [3] => Array
                    (
                        [title] => essay1 | Plagiarism | Crime & Justice - Scribd
                        [url] => https://www.scribd.com/document/252964635/essay1
                        [des] => Plagiarism is the "wrongful appropriation" and "stealing and publication" of another author's"language, thoughts, ide...
                    )

                [4] => Array
                    (
                        [title] => ARSSS
                        [url] => http://www.arsss.org/plagiarism.php
                        [des] => Plagiarism is the "wrongful appropriation" and "stealing and publication" of another author's "language, thoughts, ideas, or expressions" and the representation of them as one's own original work. Plagiarism is considered academic dishonesty and a breach of journalistic ethics.
                    )

                [5] => Array
                    (
                        [title] => Plagiarism - Plagiarism - wattpad.com
                        [url] => https://www.wattpad.com/199706948-plagiarism
                        [des] => Plagiarism is the "wrongful appropriation" and "stealing and publication" of another author's "language, thoughts, ideas, or expressions" and the representation of them as one's own original work. The idea remains problematic …
                    )

                [6] => Array
                    (
                        [title] => A DEFINITION OF PLAGIARISM - cmplt.ovh WordPress
                        [url] => https://www.compilatio.net/en/plagiarism-definition/
                        [des] => a definition of plagiarism “Plagiarism is the “wrongful appropriation” and “stealing and publication” of another author‘s “language, thoughts, ideas, or expressions,” and the representation of them as one’s own original work.
                    )

                [7] => Array
                    (
                        [title] => What is plagiarism? | Yahoo Answers
                        [url] => https://answers.yahoo.com/question/index?qid=20160301142448AALJsfV
                        [des] => Mar 01, 2016 · Plagiarism is the "wrongful appropriation" and "stealing and publication" of another author's "language, thoughts, ideas, or expressions" and the representation of them as one's own original work.[1][2] The idea remains problematic with unclear definitions and unclear rules.[3][4][5] The modern concept of plagiarism as immoral …
                    )

                [8] => Array
                    (
                        [title] => Reading: Plagiarism | ITE 115 Introduction to Computer ...
                        [url] => https://courses.lumenlearning.com/vccs-ite115-17sp/chapter/reading-plagiarism/
                        [des] => Introduction. Plagiarism is the “wrongful appropriation” and “stealing and publication” of another author’s “language, thoughts, ideas, or expressions” and the representation of them as one’s own original work.
                    )

                [9] => Array
                    (
                        [title] => Adis-Group - DEFENITION OF PLAGIARISM Plagiarism is the ...
                        [url] => https://www.coursehero.com/file/15841247/Adis-Group/
                        [des] => View Adis-Group from COMMERCE 1101 at University of Santo Tomas. DEFENITION OF PLAGIARISM Plagiarism is the "wrongful appropriation" and "stealing and publication" of another author's "language,
                    )

                [10] => Array
                    (
                        [title] => PLAGIARISM - Substantial Paper Guide - LibGuides at ...
                        [url] => http://libguides.library.arizona.edu/c.php?g=608443&p=4386531
                        [des] => There are many different definitions of plagiarism. Wikipedia defines it "as the wrongful appropriation and stealing and publication of another author's language, thoughts, ideas, or expressions and the representation of them as one's own original work."
                    )

            )

        [unique] => false
    )

)

我正在尝试获取标题密钥结果。下面是我的问题:

$data = $someArray["data"];
foreach ($data as $result) {
    foreach ($result as $finalres) {
        echo $finalres["title"]."<br/>";
    }
  }
}

这是我得到的结果。该列表正在显示,但上面和下面都显示了PHP错误。

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\naris.com.ng\check_plagia.php on line 69
 1. Plagiarism - Wikipedia
2. Plagiarism - Wikipedia
3. What is the concept of plagiarism? - ResearchGate essay1 | Plagiarism |Crime & Justice - Scribd ARSSS
4. Plagiarism - Plagiarism - wattpad.com
5. A DEFINITION OF PLAGIARISM - cmplt.ovh WordPress
6. What is plagiarism? | Yahoo Answers
7. Reading: Plagiarism | ITE 115 Introduction to Computer ...
8. Adis-Group - DEFENITION OF PLAGIARISM Plagiarism is the ...
9. PLAGIARISM - Substantial Paper Guide - LibGuides at ...

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\naris.com.ng\check_plagia.php on line 69

我不明白为什么即使在显示结果的时候警告也会一直显示?如何正确显示列表而不出现PHP错误?

EN

回答 2

Stack Overflow用户

发布于 2018-06-09 01:41:39

尝试在foreach中使用键,如

foreach ($data as $key => $result) {}

http://php.net/manual/en/control-structures.foreach.php

票数 0
EN

Stack Overflow用户

发布于 2018-06-09 01:43:56

要只输出结果,你只需要选择“webs”元素...

foreach ($data['webs'] as $result) {

你得到的错误是它第一次尝试使用...

[query] => Plagiarism is the "wrongful appropriation" and "stealing and publication"

然后迭代这段代码。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50765849

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档