php 如何解析json数组

数据库中的字段里面放的是json数据格式,
例如:$str=[{"attachment":"images\/5\/2019\/08\/ol777omFo7B2b7N977Bs9m6d6VL5bl.jpg","title":"14.jpg","cover":"0"},{"attachment":"images\/5\/2019\/08\/wzkI8P581TsPMRaM11zm5KAgaH8taL.jpg","title":"12.jpg","cover":"0"},{"attachment":"images\/5\/2019\/08\/R1r5o5Ww17VrLr2lAaR73yLyOl5im7.jpg","title":"13.jpg","cover":"0"}]
现在想将里面对应的键值取出,方法:

      $img= json_decode($str);
       foreach ($img as $value) {
           $imgarr=$value->attachment;    //取出对应的值
           $arr[]=$imgarr;      //将取出的值放入一个数组
       }

你可能感兴趣的:(php)