derrck

对数组里的元素进行排序

foreach ($info as $key=> $value)
{
 
sort($info[$key][ccnum],SORT_NUMERIC);
 
print_r($info[$key][\'ccnum\']);

数组$info是多维数组,主要排序函数是sort函数

sort(array,sorttype)

参数                                     描述
array                               必需。输入的数组。
sorttype                          可选。规定如何排列数组的值。可能的值:
                                      SORT_REGULAR - 默认。以它们原来的类型进行处理(不改变类型)。
                                      SORT_NUMERIC - 把值作为数字来处理
                                      SORT_STRING - 把值作为字符串来处理
                                      SORT_LOCALE_STRING - 把值作为字符串来处理,基于本地设置*。

例子

<?php
$my_array = array("a" => "Dog", "b" => "Cat", "c" => "Horse");

sort($my_array);
print_r($my_array);
?>
输出
Array
(
0=> Cat
[
1=> Dog
[
2=> Horse
)


分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-08-29
  • 2021-11-14
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
猜你喜欢
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
  • 2022-03-06
  • 2021-06-21
  • 2021-09-23
相关资源
相似解决方案