3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arrErros = array('teste de log 1','log vermelho com preto','log amarelo e roxo','quatro paredes em azul','azul eh a cor do oceano','no ocenano tem peixes marinhos','vermelho nao combina com azul','teste de log 1A'); //THRESHOLD PARA CÁLCULO DE SIMILARIDADE $threshold = 60; /* //INDEXAR VETOR DE PESQUISA $matriz_indexada = array(); $matriz_resultado = array(); foreach ($arrErros as $chave => $valor){ $matriz_indexada[$chave]['valor'] = $valor; $matriz_indexada[$chave]['chave'] = $chave; $matriz_indexada[$chave]['used'] = 0; } */ foreach($arrErros as $chave => $msg) { $matriz_resultado[$chave]['msg'] = $msg; $matriz_resultado[$chave]['count'] = 1; if (@$matriz_resultado[$chave]['used'] != 1) { foreach($arrErros as $chave2 => $msg2) { similar_text($msg,$msg2,$percent); if (($percent >= $threshold)){ $matriz_resultado[$chave]['msg'] = $msg; $matriz_resultado[$chave]['count']++; $matriz_resultado[$chave2]['used'] = 1; } } } } /* //CONSTRUIR VETOR DE SIMILARIDADE $totallinha = count($matriz_indexada); for ($i=0; $i<$totallinha-1; $i++){ $matriz_resultado[$i]['mensagem'] = $matriz_indexada[$i]['valor']; $matriz_resultado[$i]['count'] = 1; if ($matriz_indexada[$i]['used'] != 1){ for ($j=$i+1; $j<$totallinha; $j++){ similar_text($matriz_indexada[$i]['valor'], $matriz_indexada[$j]['valor'], $percent); if (($percent >= $threshold)){ $matriz_indexada[$j]['used'] = 1; $matriz_resultado[$i]['mensagem'] = $matriz_resultado[$i]['mensagem']; $matriz_resultado[$i]['count']++; } } } }*/ /* //ORDENAR VETOR COM BUBBLE SORT $totallinha = count($matriz_resultado); for ($i=0; $i<$totallinha-1; $i++){ for ($j=0; $j<$totallinha-1; $j++){ if ($matriz_resultado[$i]['count'] > $matriz_resultado[$j]['count']){ $mensagem = $matriz_resultado[$i]['mensagem']; $count = $matriz_resultado[$i]['count']; $matriz_resultado[$i]['mensagem'] = $matriz_resultado[$j]['mensagem']; $matriz_resultado[$i]['count'] = $matriz_resultado[$j]['count']; $matriz_resultado[$j]['mensagem'] = $mensagem; $matriz_resultado[$j]['count'] = $count; } } } */ print_r($matriz_resultado);
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Array ( [0] => Array ( [msg] => teste de log 1 [count] => 3 [used] => 1 ) [7] => Array ( [used] => 1 [msg] => teste de log 1A [count] => 1 ) [1] => Array ( [msg] => log vermelho com preto [count] => 2 [used] => 1 ) [2] => Array ( [msg] => log amarelo e roxo [count] => 2 [used] => 1 ) [3] => Array ( [msg] => quatro paredes em azul [count] => 2 [used] => 1 ) [4] => Array ( [msg] => azul eh a cor do oceano [count] => 2 [used] => 1 ) [5] => Array ( [msg] => no ocenano tem peixes marinhos [count] => 2 [used] => 1 ) [6] => Array ( [msg] => vermelho nao combina com azul [count] => 2 [used] => 1 ) )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Array ( [0] => Array ( [msg] => teste de log 1 [count] => 3 [used] => 1 ) [7] => Array ( [used] => 1 [msg] => teste de log 1A [count] => 1 ) [1] => Array ( [msg] => log vermelho com preto [count] => 2 [used] => 1 ) [2] => Array ( [msg] => log amarelo e roxo [count] => 2 [used] => 1 ) [3] => Array ( [msg] => quatro paredes em azul [count] => 2 [used] => 1 ) [4] => Array ( [msg] => azul eh a cor do oceano [count] => 2 [used] => 1 ) [5] => Array ( [msg] => no ocenano tem peixes marinhos [count] => 2 [used] => 1 ) [6] => Array ( [msg] => vermelho nao combina com azul [count] => 2 [used] => 1 ) )

preferences:
129.02 ms | 404 KiB | 164 Q