-2

我有字符串数组:

array('name is required','email is required','email is not valid','ip is not valid')

将这些字符串连接成单个字符串的最佳方法是什么:

name, email is required. email, ip is not valid
4

2 回答 2

2

The function you are looking for is called implode().

$str = implode(',',$array);

Although I didn't get the question at first, you better stick to this one. Lexical parser is not what you need for simple error messages output.

于 2013-08-27T11:09:29.380 回答
-1

在这里我给个建议

<?php
define("DELIMITER", "is");
$a = array('name is required','email is required','email is not valid','ip is not valid');
foreach($a as $k=>$v){
    $arr = explode(DELIMITER, $v, 2);
    $subject = trim($arr[0]);
    $description = trim($arr[1]);
    $res[$description][] = $subject;
}
foreach($res as $k=>$v){
    echo implode(",", $v)." ".DELIMITER." ".$k.". ";
}
echo "\n";
于 2013-08-27T11:14:24.293 回答