我需要分解不同的值,同时使用不同的分隔符,在本例中为“*”和“,”,并且我希望组元素具有相同的元素,在本例中为“car1 “
使用示例,我在使用爆炸时尝试使用相同元素的组元素,但最后不要
<?php
/// Values to Explode
$a="house1,car1,phone1*house2,car1,phone2*house3,car3,phone3*";
/// First Explode
$exp_1=explode("*",$a);
/// Loop Explode with "*"
foreach($exp_1 as $exps)
{
$exps=explode(",",$exps);
/// Here i want group the arrays or elements contain the same - car1 - in this case 1 and 2 arrays
/// I try do this but don´t works ///
if ($exps[1]==$exps[1])
{
/// Must show house1,car1,phone1 and house2,car1,phone2 because have the same car called car1, and group en each case, common element it´s car1
print "ok";
}
else
{
print "Others";
}
}
?>
答案 0 :(得分:0)
使用preg split:
$a = "house1,car1,phone1*house2,car1,phone2*house3,car3,phone3*";
$parts = preg_split('/[*|,]/', $a);
var_dump ($parts);