2016-09-29 66 views
0

如何列出以“Toutes lescatégories”开头的表格?下面 的代码显示开始 “动物德COMPAGNIE” 的表...排序数组不是字母PHP

public function __category_nice_name($categ_name) { 
     $ret = $categ_name; 

     $special = array('AllCategories' => '`Toutes les catégories`', 'MP3Downloads' => 'Téléchargements MP3', 'PCHardware' => 'Matériel informatique', 'VHS' => 'VHS', 'Apparel' => 'Habillement', 'Appliances' => 'Électroménager', 'Automotive' => 'Automobile', 'Beauty' => 'Beauté', 'Baby' => 'Bébé', 'Books' => 'Livres', 'Classical' => 'Classique', 'Electronics' => 'Électronique', 'ForeignBooks' => 'Livres étrangères', 'Grocery' => 'Nourriture', 'HomeGarden' => 'Loisirs, Maison & Jardin', 'Jewelry' => 'Bijoux', 'Kitchen' => 'Cuisine', 'Lighting' => 'Éclairage', 'Luggage' => 'Valises et Sacs de voyage', 'Magazines' => 'Magazine', 'MusicalInstruments' => 'Equipement DJ et VJ', 'OfficeProducts' => 'Fournitures scolaires et de bureau', 'OutdoorLiving' => 'Outdoor', 'Outlet' => 'Sale', 'PetSupplies' => 'Animal de compagnie', 'Shoes' => 'Chaussures', 'SportingGoods' => 'Sports & Loisirs', 'Tools' => 'Outils', 'Toys' => 'Jouets', 'Watches' => 'Montres'); 
     if (!in_array($categ_name, array_keys($special))) { 
      $ret = preg_replace('/([A-Z])/', ' $1', $categ_name); 
     } else { 
      $ret = $special["$categ_name"]; 
     } 
     return $ret; 
    } 

回答

1

的HelloWorld 可以使用

sort (array) 

如:

<?php 

$fruits = array("lemon", "orange", "banana", "apple"); 
sort($fruits); 
foreach ($fruits as $key => $val) { 
    echo "fruits[" . $key . "] = " . $val . "\n"; 
} 
    //fruits[0] = apple 
    //fruits[1] = banana 
    //fruits[2] = lemon 
    //fruits[3] = orange 
?> 

此功能阶小INT到更大的整数,但如果你没有整数,它做一个aphabetical订单rtm这里http://php.net/manual/fr/function.sort.php