quinta-feira, 20 de agosto de 2015

Array em ordem alfabética Brasil - Array Usort (character accentuation)


Primeiro coloque no topo do pagina
First on the top of the page

setlocale(LC_ALL, "pt_BR", "ptb"); // works for Linux and Windows

Depois monte sua página

function cmp($a, $b) {
    return strcmp($a["first_name"], $b["first_name"]);
}

$docs = array(
    1 => array(
        'first_name' => 'Márcia Amanda',
        'crm' => 4321,
        'job' => 'Médica',
        'sex' => 'f'
    ),
    2 => array(
        'first_name' => 'Pedro Alexandre',
        'crm' => 6789,
        'job' => 'Veterinário',
        'sex' => 'm'
    ),
    3 => array(
        'first_name' => 'Lívia Pereira',
        'crm' => 8765,
        'job' => 'Obstetra',
        'sex' => 'f'
    )
);

usort($docs, "cmp", SORT_LOCALE_STRING);

                                $qtas_pessoas = count($docs);
                              
                                $j=1;
                               
                                while (list($key, $value) = each($docs)) {
                               
                                if ($j==1) echo "<div class='wrapper indent-bottom7-1'>";
                               
                                $dr='';
                                if ($value["sex"]=='m') $dr='Dr.';
                                else $dr='Dra.';
                               
                                echo "
                                <div class='grid_4 alpha'>
                                    <h6 class='p2'>$dr ".$value["first_name"]."<br/>CRM ".$value["crm"]."</h6>
                                    ".$value["job"]."
                                </div>\n
                                ";
                               $j++;
                               if ($j>$qtas_pessoas) {
                                   echo "</div>";
                                   break; // TEMOS APENAS X PESSOAS...
                               }
                               // quebrar sempre de 3 em 3
                               if ($j % 3 == 1) echo "</div><div class='wrapper indent-bottom7-1'>";
                                }

Nenhum comentário:

Postar um comentário

Linux bash file returns unexpected token `$'do\r''

open file in vi edit with   vi filename.sh   command; type in vi  :set ff=unix  command; save file with  :wq It will save the file with unix...