首頁  >  文章  >  後端開發  >  问基础有关问题

问基础有关问题

WBOY
WBOY原創
2016-06-13 11:15:13846瀏覽

问基础问题

    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;

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn