0

我有一些数据存储在单列 mysql DB 中,如下所示:

1-Yizle-smallpic-this is pretty cool-2-User-smallpic-testing!1-Yizle-smallpic-this is pretty cool-2-User-smallpic-testing!-

现在我想在 for 循环中输出该数据,并需要它每 4 个连字符循环一次,因为数据输出将是

$uid,$username,$userpicurl,$comment..

到目前为止,我的代码显然有效,但只返回第一次出现。

foreach($result->fetch_assoc() as $v){
    list($uid, $username, $userpicurl, $comment) = explode("-", $v); print "$uid $username $userpicurl $comment";
}
4

1 回答 1

0
foreach($result->fetch_assoc() as $v) {
    $parts = explode("-", $v);
    for ($i = 0; $i < count($parts); $i+=4) {
        list($uid, $username, $userpicurl, $comment) = array_slice($parts, $i, 4);
        print "$uid $username $userpicurl $comment";
    }
}
于 2013-08-20T01:41:24.457 回答