$str = "153+张三,李四+12,11,135||154+王五,小明+124,234,345";
// 分割字符串为多个子字符串
$sections = explode("||", $str);
// 遍历每个子字符串
foreach ($sections as $section) {
// 分割子字符串为 ID、Name、Uid
$idNameUid = explode("+", $section);
$id = $idNameUid[0];
$name = $idNameUid[1];
$uid = $idNameUid[2];
//array(2) { [0]=> array(3) { ["id"]=> string(3) "153" ["name"]=> string(13) "张三,李四" ["uid"]=> string(9) "12,11,135" } [1]=> array(3) { ["id"]=> string(3) "154" ["name"]=> string(13) "王五,小明" ["uid"]=> string(11) "124,234,345" } }
$arr[] = ['id'=>$id,'name'=>$name,'uid'=>$uid];
}
PHP 字符串切割,组装二维数组的键值对
于 2023-10-19 14:27:21 首次发布