PHP使用逗号分隔数据,然后为每个做些什么?

时间:2018-12-01 13:39:23

标签: php arrays

一个字符串存储在数据库中,该字符串可以具有更多或更少的条目。通常这不是一个问题,但是当一个以上的问题解决时,这将是一件很不错的事情。没有固定数量的条目(无限制),因此要求第二个条目等...不适用于更多条目。

非常感谢您的帮助!

PHP版本:7.2

$string = '649374658494, 74658397464, 746384946354, 8659584748';
$var = explode(',',$string);
foreach($var as &$value){   
    $value = '<p>' .$var. '</p>';
}

1 个答案:

答案 0 :(得分:2)

这是一个简单的错误。 db.records.update({"key" : "ABC-111"},{$pull: {"listChgLogs": {"changelog": {"items": {"fields": "Fix Version"}}}}}) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 }) db.records.update({"key" : "ABC-111"},{$pull: {"listChgLogs.$.changelog.items": {"fields": "Fix Version"}}}) WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0, "writeError" : { "code" : 2, "errmsg" : "The positional operator did not find the match needed from the query." } }) 应该是echo $var

$value

启用error reporting会显示类似以下内容:

  

注意:数组到字符串的转换...

...为了避免在答案中出现链接,您可以启用简单的错误报告,例如:

    $string = '649374658494, 74658397464, 746384946354, 8659584748';
    $var = explode(',',$string);
    $nvalue="";
    foreach($var as &$value){   
        $nvalue .= '<p>' .$value. '</p>';
    }
    echo $nvalue;