我有一个字符串数组:
array('name is required','email is required','email is not valid','ip is not valid')
将这些字符串连接成单个字符串的最佳方法是什么:
name, email is required. email, ip is not valid
答案 0 :(得分:2)
您正在寻找的功能称为implode()。
$str = implode(',',$array);
虽然我最初没有得到这个问题,但你最好坚持这个问题。词法分析器不是简单错误消息输出所需的。
答案 1 :(得分:-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";