Php 数组中的while循环?

Php 数组中的while循环?,php,arrays,while-loop,Php,Arrays,While Loop,我想知道我是否能够在数组中执行while循环 while($row = $retail -> fetch(PDO::FETCH_ASSOC)){ $json['data'][] = array( 'id'=>$row['idretailers'], "category"=>$row['category'], "headline"=>$row['headline'], 'price'=> array ("full_price" => $row['price'

我想知道我是否能够在数组中执行while循环

while($row = $retail -> fetch(PDO::FETCH_ASSOC)){

$json['data'][] = array(

'id'=>$row['idretailers'],
"category"=>$row['category'],
"headline"=>$row['headline'],
'price'=> array ("full_price" => $row['price']),
'description'=>$row['description'],
"comments" => array(
while($row_c = $comments -> fetch(PDO::FETCH_ASSOC)){

 // more items  
})
);
}
评论中有一个while循环,可能吗


谢谢

您编写它的方式是不可能的,但有一个简单的解决方案:

"comments" => $comments -> fetchAll(PDO::FETCH_ASSOC)

您编写它的方式是不可能的,但有一个简单的解决方案:

"comments" => $comments -> fetchAll(PDO::FETCH_ASSOC)

由于要将其插入到JSON字符串中,请执行以下操作:

while($row = $retail -> fetch(PDO::FETCH_ASSOC)){

    $json['data'][] = array(

        "id"=>$row['idretailers'],
        "category"=>$row['category'],
        "headline"=>$row['headline'],
        "price"=> array ("full_price" => $row['price']),
        "description"=>$row['description'],
        "comments" => $comments->fetchAll()
    );
}
否则,您可以访问以下评论:

while($row = $retail -> fetch(PDO::FETCH_ASSOC)){

    $json['data'][] = array(

        "id"=>$row['idretailers'],
        "category"=>$row['category'],
        "headline"=>$row['headline'],
        "price"=> array ("full_price" => $row['price']),
        "description"=>$row['description'],
        "comments" => implode("\n", $comments->fetchAll());
    );
}

由于要将其插入到JSON字符串中,请执行以下操作:

while($row = $retail -> fetch(PDO::FETCH_ASSOC)){

    $json['data'][] = array(

        "id"=>$row['idretailers'],
        "category"=>$row['category'],
        "headline"=>$row['headline'],
        "price"=> array ("full_price" => $row['price']),
        "description"=>$row['description'],
        "comments" => $comments->fetchAll()
    );
}
否则,您可以访问以下评论:

while($row = $retail -> fetch(PDO::FETCH_ASSOC)){

    $json['data'][] = array(

        "id"=>$row['idretailers'],
        "category"=>$row['category'],
        "headline"=>$row['headline'],
        "price"=> array ("full_price" => $row['price']),
        "description"=>$row['description'],
        "comments" => implode("\n", $comments->fetchAll());
    );
}

只要尝试一下,就会发现语法错误,并尝试另一种方法。肖特:不,这是不可能的。@Khurram这是薛定谔的参考资料吗?@deceze这是我自己的理解:-D,我以前不知道那个伟大的科学家,thx分享他的名字,thx分享给维基,cheers@JohnConde我确实试过了。我想问一下,我应该采取哪种方法来完成类似的事情。只要尝试一下,就会发现语法错误,然后尝试另一种方法。肖特:不,这是不可能的。@Khurram这是薛定谔的参考资料吗?@deceze这是我自己的理解:-D,我以前不知道那个伟大的科学家,thx分享他的名字,thx分享给维基,cheers@JohnConde我确实试过了。我想问我应该采取哪种方法来完成类似的事情。+1和回答示例的完整脚本,以及其他方法方法+1和回答示例的完整脚本,以及其他方法方法