Home >Backend Development >PHP Tutorial > 问基础有关问题

问基础有关问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 12:53:36940browse

问基础问题

    public function match_stuff($content){<br />
       $artlist = pq('.stepcont');<br />
       foreach($artlist as $li){<br />
        $stuff[] -> approved = pq($li)->find('p')->text();<br />
        if($stuff){<br />
        $stuff[] -> kkli = pq($li)->find('a img')->attr('src');<br />
}}<br />
    return $stuff;<br />
    }

现在转json后是这个效果
[<br />
    {<br />
        "approved": "wwwwwww"<br />
    },<br />
    {<br />
        "kkli": "33333333333333"<br />
    },<br />
    {<br />
        "approved": "444444444444444"<br />
    },<br />
    {<br />
        "kkli": "55555555555"<br />
    },<br />
    {<br />
        "approved": "6666666666"<br />
    },<br />
    {<br />
        "kkli": "7777777777777777"<br />
    },<br />
    {<br />
        "approved": "88888888888"<br />
    },<br />
    {<br />
        "kkli": "999999999999"<br />
    },<br />
    {<br />
        "approved": "0000000000000"<br />
    },<br />
    {<br />
        "kkli": "111111111111111"<br />
    },<br />
    <br />
]


我想要这个效果,上面应该怎么改? 
[<br />
    {<br />
        "approved": "wwwwwww","kkli": "33333333333333"<br />
    },<br />
<br />
    {<br />
        "approved": "444444444444444","kkli": "55555555555"<br />
    },<br />
<br />
    {<br />
        "approved": "6666666666","kkli": "7777777777777777"<br />
    },<br />
    {<br />
        "approved": "88888888888","kkli": "999999999999"<br />
    },<br />
    {<br />
        "approved": "0000000000000","kkli": "111111111111111"<br />
    },<br />
    <br />
]

直接贴上代码来谢谢


------解决方案--------------------
$artlist = pq('.stepcont');<br />
foreach($artlist as $li){<br />
  $stuff[] = array(<br />
    'approved' => pq($li)->find('p')->text(),<br />
    'kkli' => pq($li)->find('a img')->attr('src')<br />
  );<br />
}<br />
return $stuff;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn