From the form comes the data that must be parsed regular. The result is an array of the form
Array ( [0] => Array ( [0] => Зачаровать Оружие [12] F [1] => Зачаровать Оружие [2] => 12 [3] => [4] => F ) [1] => Array ( [0] => Зачаровать Оружие [12] F [1] => Зачаровать Оружие [2] => 12 [3] => [4] => F )
I need to receive an array of a type
Array ( [Зачаровать Оружие] => Array ( [0] => Зачаровать Оружие [11] (x2) VP [1] => Зачаровать Оружие [2] => 11 [3] => 2 [4] => VP ) [Зачаровать Обувь] => Array ( [0] => Зачаровать Обувь [11] VP [1] => Зачаровать Обувь [2] => 11 [3] => [4] => VP ) [Зачаровать Поножи] => Array ( [0] => Зачаровать Поножи [11] VP [1] => Зачаровать Поножи [2] => 11 [3] => [4] => VP )
In other words, so that each category of things contains a subcategory of things that belongs to the main category. I implemented some kind of option, but I got a lot of duplicate code, tell me how you can implement it easier.
function parseInfo($data,$category) { $matches = array(); switch($category){ case "charki" : $pattern = "/(Зачаровать\s\D{1,8})\s\[(\d{1,2})\].{1,3}?(\d{1,2})?.{1,3}?([PVFERUL]+)/u";break; } preg_match_all($pattern,$data,$found,PREG_SET_ORDER); foreach($found as $item){ $itemCat = $item[1]; $thing = $item[1]." ".$item[2]." ".$item[4]; if(isset($matches[$itemCat])){ if(isset($matches[$itemCat][$thing])){ }else{ $matches[$itemCat][$thing] = $item; } }else{ if(isset($matches[$itemCat][$thing])){ }else{ $matches[$itemCat][$thing] = $item; } } } return $matches; }