R
R
Roman Kuzmenko2015-12-15 11:27:45
PHP
Roman Kuzmenko, 2015-12-15 11:27:45

How to sort names correctly in php?

All the same, the question remained ...
I used it like this:

usort($results, function($a, $b){
return strcmp(str_replace('.', '', $a['name']), str_replace('.', '', $b['name']));
});

Received the following (forgive me for such a long list, put all that there should be clear):
ABK
ABSOLUTE KERAMIKA the
ACA CERAMICAS
ACIF
ADEX
Alcalagres
ALCO's CERAMICHE
ALTA
APARICI
APE CERAMICA
ARCANA
ARTICER the
ATLAS CONCORDE
AURELIA CERAMICHE the
AVA CERAMICS
AZULEJERA ALCORENSE azulejos
ALCOR
ABITA
ACALAGRES
ALAPLANA
ALCALATEN CERAMICAS
Aleluia
ALFA
ALFALUX CERAMICHE
ALTTOGLASS
AMADIS
APAVISA
ARANDA
ARCHEO CERAMICA
ARGENTA
ARIANA
ARIOSTEA
ART CASA BY COMEDIL
ASCOT
ATENEA
ATLANTICTILESPROJECTS
AZAHAR
AZORI
AZTECA
AZTECA NATURE
AZULEJO ESPANOL AZULEJOS BENADRESA AZULEJOS
BORJA
AZULEJOS
EL MIJARES AZULEJOS
MALLOL
AZULEV
AZULIBER
AZULINDUS & MARTI

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cat Anton, 2015-12-15
@devrvk

Cast strings to the same case if you want to sort case-insensitively:

usort($results, function ($a, $b) {
    return strcmp(
        strtoupper(str_replace('.', '', $a['name'])), 
        strtoupper(str_replace('.', '', $b['name']))
    );
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question