在foreach循环中使用PHP解析数组

时间:2015-10-24 07:35:49

标签: php arrays

我想用PHP的foreach循环解析数组,以获取'ques'数组中的对象名称和值。

[
{
"ques": [
    {
        "name": "comment",
        "value": "comment me for the reason",
        "sur_id": "1",
        "user_id": "admin@gmail.com",
        "pagename": "question_response"
    },
    {
        "name": "check-box[]",
        "value": "1"
    },
    {
        "name": "radio",
        "value": "radio 2"
    },
    {
        "name": "yes",
        "value": "no"
    }

]
"ques":[
{
        "name": "date",
        "value": "2015-10-23"
    },
    {
        "name": "select-deopdown",
        "value": ""
    },
    {
        "name": "true",
        "value": "false"
    },
    {
        "name": "number",
        "value": "55"
    }
]
}

我想将值与'ques'数组分开:

while ($fetch = mysql_fetch_array($query1)) {
   $content = $fetch['CONTENT_VALUES'];
  // print_r($content);
  $content_value= mb_convert_encoding($content ,"UTF-8");
    $datas = json_decode($content, true);
     foreach($datas->ques as $values)
     {
         echo $values->value . "\n";
          print_r($values);
     }
   $test[] = array('ques' =>  $datas ,'answer'=>$values);
}

0 个答案:

没有答案