PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Case insensitive ksort
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Case insensitive ksort

Réponse
 
LinkBack Outils de la discussion
Vieux 18/09/2007, 16h37   #1 (permalink)
Christoph Boget
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Case insensitive ksort

I looked in the docs but didn't see anything regarding case
insensitivity and I fear the functionality doesn't exist. I'm just
hoping I'm looking in the wrong place.

Is there a way to get ksort to work without regard to case? When I
sort an array using ksort, all the upper case keys end up at the top
(sorted) and all the lower case keys end up at the bottom (sorted).
Ideally, I'd like to see all the keys sorted (and intermixed)
regardless of case. Am I going to have to do this manually? Or is
there an internal php command that will do it for me?

thnx,
Christoph
  Réponse avec citation
Vieux 18/09/2007, 16h45   #2 (permalink)
Jim Lucas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Case insensitive ksort

Christoph Boget wrote:
> I looked in the docs but didn't see anything regarding case
> insensitivity and I fear the functionality doesn't exist. I'm just
> hoping I'm looking in the wrong place.
>
> Is there a way to get ksort to work without regard to case? When I
> sort an array using ksort, all the upper case keys end up at the top
> (sorted) and all the lower case keys end up at the bottom (sorted).
> Ideally, I'd like to see all the keys sorted (and intermixed)
> regardless of case. Am I going to have to do this manually? Or is
> there an internal php command that will do it for me?
>
> thnx,
> Christoph
>


Is this what you are looking for?

<?php

$yourarray = array();

$sorted = natcasesort(array_keys($yourarray));

foreach ( $sorted AS $key ) {
echo $yourarray[$key];
}

?>

--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare
  Réponse avec citation
Vieux 18/09/2007, 16h57   #3 (permalink)
Robin Vickery
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Case insensitive ksort

On 18/09/2007, Christoph Boget <christoph.boget@gmail.com> wrote:
> I looked in the docs but didn't see anything regarding case
> insensitivity and I fear the functionality doesn't exist. I'm just
> hoping I'm looking in the wrong place.
>
> Is there a way to get ksort to work without regard to case? When I
> sort an array using ksort, all the upper case keys end up at the top
> (sorted) and all the lower case keys end up at the bottom (sorted).
> Ideally, I'd like to see all the keys sorted (and intermixed)
> regardless of case. Am I going to have to do this manually? Or is
> there an internal php command that will do it for me?


uksort($array, 'strcasecmp');

-robin
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 10h57.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08873 seconds with 11 queries