title: categorised multidimensional string and filter
body: <p>I have a multidimensional string as follows</p>
  <pre><code>$string = '(car)hyundai|(car)bmw|(car)tesla|(bus)abc|(bus)cde|(cycle)are|(cyele)dyd|......'
  </code></pre>
  <p>I want to categorized the items in vehicles (car, bus, cycle..) and create a radio button based on the vehicles</p>
  <pre><code>&lt;input type = &quot;radio&quot; value=&quot;car&quot;&gt; 
  &lt;input type = &quot;radio&quot; value=&quot;bus&quot;&gt; 
  </code></pre>
  <p>and do an onclick event to display the value for each categories
  So If I click car, then all the car values needs to be displayed (e.g. hyunday, bmw, tesla)</p>
  <p>so Far I have done this</p>
  <pre><code> $mainData = explode('|', $string);
   $data1 = [];
   $category =[];
   $subcategory =[];
   $i=0;
   foreach($mainData as $data){
       $data2 = explode(')', $data);
       $data1[$data2[0]][] = $data2[1];
     }  
  
     foreach ($data1 as $data3 =&gt; $dataContents) {
       $datas[$data3] = array_unique($dataContents);
       array_push($category,  $data3);
       array_push($subcategory, $datas[$data3]);                   
     }
  </code></pre>
  <p>I can separate the data but couldn't filter the data. Any idea would be highly appreciated</p>