<?php

error_reporting(-1);

$regexp = "/(([а-я]+[a-z]+)|([a-z]+[а-я]+))\\w*/ui";//Expression for searching latin letters among cyrillics in words
$wordRegexp = "/[a-z]/ui"; //Expression for pick out latin letter and replaced by cyrillic
$string = "Пocтaвкa мяco гoвядины, бecкостнoe для нужд государственного бюджетного учреждения здравоохранения Республики Башкортостан Инфекционная клиническая больница № 4 города Уфа  \n";
$matches = []; // array for pick words with latin letters
$subjects = [];// array for replaced latin letters
$wordTemplate = array(
  'a' => 'а', 
  'c' => 'с',
  'o' => 'о',
  'e' => 'е',
  'y' => 'у',
  'x' => 'х',
  'p' => 'р',
);//array with replacement template
preg_match_all($regexp, $string, $matches); // pick out words
$matches = $matches[0]; // All words are located in 0 array in array matches that operation rewrite array.
for ($i=(count($matches)-1); $i>=0; $i--) {
  $problemWord = $matches[$i];
  echo "Line: $problemWord \n"; // just for check
  preg_match_all($wordRegexp, $problemWord, $subjects);
  $subjects = $subjects[0];// operation like in 20 line
  for ($j=(count($subjects)-1); $j>=0; $j--) { // pick out latin letters
    $problemLetter = $subjects[$j];
    echo "Line_subjects: $problemLetter \n";// just for check
    foreach ($wordTemplate as $key => $value) { // searching similar letter in tamplate 
      if ($key == $problemLetter) {
        $letterRegexp = "/$key/ui";
        $problemWord = preg_replace($letterRegexp, "[{$value}]", $problemWord);
      }
    }
  }
  echo "problemWord after foreach: $problemWord \n";
} 
?>