方法一
//假定以“;”为每组词的分割符
03 $text = 'a->b;b->a;c->a;a->c';
04 $arr = explode(";", $text);
05 $arrSorted = array();
立即学习“PHP免费学习笔记(深入)”;
06 foreach($arr as $str) {
07 list($front, $back) = explode("->", $str);
08 //将唯一的字符串保存在$arrSorted的键值里
09 if (!isset($arrSorted[$front.$back]) and !isset($arrSorted[$back.$front])) {
10 $arrSorted[$front.$back] = $front.'->'.$back;
11 }
12 }
13 //打印
14 foreach($arrSorted as $str) {
15 echo $str . '
';
16 }
方法二
$reg1 = 'a->b';
$content; //这里是你所有的内容
preg_match_all($reg1, $content, $match); //这里得到的是所有的'a->b'的内容存为数组
preg_replace($reg1, '', $match);
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号