private static function AssignMatvid($material_name1c) { // Определяем Вид материальной ценности Proc::mb_preg_match_all('/[а-яА-Яa-zA-Z\\d]+/u', $material_name1c, $match_arr, PREG_OFFSET_CAPTURE, 0, 'UTF-8'); $i = 0; $tmpmin = [1, '']; while ($i < count($match_arr[0])) { $word = $match_arr[0][$i]; $str = mb_substr($material_name1c, 0, $word[1], 'UTF-8') . $word[0]; $rows = Importmaterial::model()->FindAll(['condition' => "importmaterial_combination LIKE :importmaterial_combination", 'params' => [':importmaterial_combination' => $str . '%'], 'order' => 'CHAR_LENGTH(importmaterial_combination)']); if (count((array) $rows) === 1 && mb_stripos($material_name1c, $rows[0]['importmaterial_combination'], 0, 'UTF-8') === 0 || count((array) $rows) > 1) { $tmpmin = [$rows[0]['id_matvid'], $rows[0]['importmaterial_combination']]; } else { break; } $i++; } // Если Вид материальной ценности не определен, то ставится ключ 1 со значением "Не определен" return $tmpmin[0]; }