I tried this
$data = "air;air;air;bus;air;air;bus;air;air";
$a = substr_count($data,"air");
$b = substr_count($data,"bus");
$data = implode($a . ' x ', array_unique(explode('air;', $data)));
echo $data;
And I get
7 x bus;7 x air
What I actually want to get is
7 x air 2 x bus
Help please..
echo implode($a . ' x ', array_unique(explode('air;', $data)));- that makes so little sense, I would not even know where to start ... Just explode your string at the;, and then use php.net/manual/en/function.array-count-values.phpecho $a . ' x air ' . $b . ' x bus';...?