3v4l.org

run code in 300+ PHP versions simultaneously
<?php $args = []; $key = 'subFunction'; $value = 'Administratif,Asset Management,CTO,Administratif,Asset Management,CTO,Administratif,Asset Management,CTO'; //$listName = $this->parserDOM[$key][4]; //echo 'listName =>> ' . $listName . PHP_EOL; //// Retrieve the list and store it in an array //if ($listName) { // $list = []; // $qry = wh_get_select_qry('contents_lists', array('list' => $listName)); // $qry = str_replace('*', '`id_unique`, `title_1`', $qry); // $res = $this->sqli->query($qry); // while ($row = $res->fetch_assoc()) { // $list[$row['id_unique']] = $row['title_1']; // } //} $list = [ 'achats' => 'Achats', 'administratif' => 'Administratif', 'asset-management' => 'Asset Management', 'audit' => 'Audit', 'comptabilite' => 'Comptabilité', 'controle-de-gestion' => 'Contrôle de Gestion', 'crm' => 'CRM', 'daf' => 'DAF', 'data' => 'Data', 'dev-commercial' => 'Dév commercial', 'digital' => 'Digital', 'erp' => 'ERP', 'expertise-comptable' => 'Expertise comptable', 'formation' => 'Formation', 'gestion-multisite' => 'Gestion multisite', 'gestion-projets' => 'Gestion projets', 'immobilier' => 'Immobilier', 'it' => 'IT', 'juridique' => 'Juridique', 'logistique' => 'Logistique', 'mandat-ad-hoc-conciliation' => 'Mandat ad-hoc / conciliation', 'marque' => 'Marque', 'media' => 'Média', 'mep-process' => 'MEP process', 'offre' => 'Offre', 'omnicanal' => 'Omnicanal', 'outil-si' => 'Outil SI', 'paie' => 'Paie', 'production' => 'Production', 'produits-offre' => 'Produits - offre', 'projet' => 'Projet', 'qualite' => 'Qualité', 'rel-sociales' => 'Relations Sociales', 'rh' => 'RH', 'rse' => 'RSE', 'sirh' => 'SIRH', 'supply-chain' => 'Supply chain', 'transformation' => 'Transformation', 'tresorerie' => 'Trésorerie', 'cto' => 'CTO', 'cpo' => 'CPO', 'cdo' => 'CDO', ]; //print_r($list); //echo PHP_EOL; // Check the matching between arg value and list value if ($list) { $multiselectValues = explode(',', $value); // echo 'multiselectValues =>>'; // print_r($multiselectValues); // echo PHP_EOL; foreach ($multiselectValues as $valueKey => $multiselectValue) { $multiselectKeyFromValue = wh_clean_string_from_special_chars($multiselectValue); // echo '$multiselectKeyFromValue =>>'; // print_r($multiselectKeyFromValue); // echo PHP_EOL; // echo '$multiselectValue =>>'; // print_r($multiselectValue); // echo PHP_EOL; // echo 'in_array =>>'; // print_r(in_array($multiselectKeyFromValue, array_keys($list))); // echo PHP_EOL; // echo 'array_search =>>'; // print_r(array_search($multiselectValue, $list)); // echo PHP_EOL; if (in_array($multiselectKeyFromValue, array_keys($list)) || $multiselectKey = array_search( $multiselectValue, $list )) { echo '$multiselectKey =>>'; print_r($multiselectKey); echo PHP_EOL; $multiselectValues[] = $multiselectKey ?? $multiselectKeyFromValue;; echo '$multiselectValues add =>>'; print_r($multiselectValues); echo PHP_EOL; unset($multiselectValues[$valueKey]); unset($multiselectKey); echo '$multiselectValues unset =>>'; print_r($multiselectValues); echo PHP_EOL; // If there is no match with list key or value, include the custom list if the file exist } elseif (!array_key_exists($multiselectValue, $list)) { echo 'multiselectValue elseif =>>' . $multiselectValue; echo PHP_EOL; } } } $args[$key] = json_encode($multiselectValues); print_r($args); echo PHP_EOL; /** * The wh_clean_string_from_special_chars function will clean a string replacing the special character by the character passed in parameter. * * It will also delete the spaces before and after the text. And the accents. * * @param string $string Text to clean * @param string $replacement (optional) Character to replace the special characters. Default: '-' * * @return string Cleaned text */ function wh_clean_string_from_special_chars($string,$replacement = '-') { // les accents $string = trim($string); //$string = strtr(utf8_decode($string),"ÀÃ�ÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÃ�ÃŽÃ�ìíîïÙÚÛÜùúûüÿÑñ","aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn"); $string = str_replace( array('à','á','â','ã','ä', 'ç', 'è','é','ê','ë', 'ì','í','î','ï', 'ñ', 'ò','ó','ô','õ','ö', 'ù','ú','û','ü', 'ý','ÿ', 'À','Ã�','Â','Ã','Ä', 'Ç', 'È','É','Ê','Ë', 'ÃŒ','Ã�','ÃŽ','Ã�', 'Ñ', 'Ã’','Ó','Ô','Õ','Ö', 'Ù','Ú','Û','Ü', 'Ã�'), array('a','a','a','a','a', 'c', 'e','e','e','e', 'i','i','i','i', 'n', 'o','o','o','o','o', 'u','u','u','u', 'y','y', 'A','A','A','A','A', 'C', 'E','E','E','E', 'I','I','I','I', 'N', 'O','O','O','O','O', 'U','U','U','U', 'Y'), $string ); // REPLACE ACCENTS MADE WITH TWO CHARACTERES (ACCENT + LETTER) $string = str_replace(array('aÌ€', 'aÌ�', 'aÌ‚', 'ã', 'ä', 'ç', 'eÌ€', 'eÌ�', 'eÌ‚', 'ë', 'iÌ€', 'iÌ�', 'iÌ‚', 'ï', 'ñ', 'oÌ€', 'oÌ�', 'oÌ‚', 'õ', 'ö', 'uÌ€', 'uÌ�', 'uÌ‚', 'ü', 'yÌ�', 'ÿ', 'AÌ€', 'AÌ�', 'AÌ‚', 'Ã', 'Ä', 'Ç', 'EÌ€', 'EÌ�', 'EÌ‚', 'Ë', 'IÌ€', 'IÌ�', 'IÌ‚', 'Ï', 'Ñ', 'OÌ€', 'OÌ�', 'OÌ‚', 'Õ', 'Ö', 'UÌ€', 'UÌ�', 'UÌ‚', 'Ü', 'YÌ�', '​'), array('à', 'á', 'â', 'ã', 'ä', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'À', 'Ã�', 'Â', 'Ã', 'Ä', 'Ç', 'È', 'É', 'Ê', 'Ë', 'ÃŒ', 'Ã�', 'ÃŽ', 'Ã�', 'Ñ', 'Ã’', 'Ó', 'Ô', 'Õ', 'Ö', 'Ù', 'Ú', 'Û', 'Ü', 'Ã�', ''), $string); // les caracètres spéciaux (aures que lettres et chiffres en fait) $string = preg_replace('/([^.a-z0-9]+)/i', $replacement, $string); $string = strtolower($string); return $string; }

preferences:
33.7 ms | 414 KiB | 5 Q