2
Hello, I have a problem, I need to sort a set of letters in alphabetical order, but the word order is customized from a specific order of letters.
<?php
// Pega o conteudo do arquivo texto.
$arquivo = file_get_contents("texto.txt") or die("Falha ao pega o conteudo!");
// Pega as palavras do arquivo e guarda cada palavra em uma posição da array.
$resultado = explode(" ", $arquivo);
$ordenado = array();
//array de inicialização do alfabeto booglan
function cmpA($a,$b){
$alfabeto_boo = array('t','w','h','z','k','d','f','v','c','j','x','l','r','n','q','m','g','p','s','b');
if(strcmp(substr($a, 0,1), substr($b, 0,1)) == 0){
echo "$a:$b<br>";
return 0;
}
return (array_search($a,$alfabeto_boo) < array_search($b,$alfabeto_boo)) ? -1 : 1;
}
usort($resultado, "cmpA");
echo '<pre>' . print_r($resultado,true) . '</pre>';
?>
But with the usort, it’s returning me sorter, but not in the order determined by the proposed alphabet.
You can edit the question you asked earlier, than create another, if the purpose is the same. Then it goes to reopening
– vinibrsl
I tried, but it didn’t roll. I don’t know what happened, I’m also new around here.
– Luiz Miguel
About the purpose, they are not equal, but have the best idea, in the other topic, I already manage to solve.
– Luiz Miguel