Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
数组php的排序数组_Php_Arrays_Codeigniter_Associative - Fatal编程技术网

数组php的排序数组

数组php的排序数组,php,arrays,codeigniter,associative,Php,Arrays,Codeigniter,Associative,我正在从事一个基于codeigniter的小项目,我不是php开发人员,这是我的问题: foreach ($checkeds['id_iscritti'] as $checked){ $iscritto = $this->pellegrinaggio_iscritti_m->get_iscritto($checked); $utente = $this->utenti_m->get_utente($iscritto[0]-

我正在从事一个基于codeigniter的小项目,我不是php开发人员,这是我的问题:

       foreach ($checkeds['id_iscritti'] as $checked){

        $iscritto = $this->pellegrinaggio_iscritti_m->get_iscritto($checked);

        $utente = $this->utenti_m->get_utente($iscritto[0]->id_utente);

        echo ("utente:   <pre> ");var_dump($utente);echo ("   </pre> \n\n");

    }
如何按索引“nome”对数组$utenti进行排序?
我花了几个小时来了解这种阵列是如何工作的,没有任何结果,你能帮我吗?

这就是你想要的功能:

您的代码应该如下所示:

usort($utente, function($a, $b){
   if ($a->nome > $b->nome) {
      return 1;
   }elseif($a->nome < $b->nome){
      return -1;
   }else{
     return 0;
   }
});
PHPs usort()函数允许您使用自定义函数对数组进行排序

假设您的对象数组存储在
$ute
中,下面将使用匿名比较函数将每个对象与其他对象进行比较

在下面的代码中,
$utete
数组将按
nome
值升序排序

usort($utete,function($a,$b){
如果($a->nome>$b->nome){
返回1;
}elseif($a->nome<$b->nome){
返回-1;
}否则{
返回0;
}
});

有关更多详细信息,请访问

如果我错了,请纠正我的错误,但我确信
array\u multisort()
只对数组进行排序,而不是对对象数组进行排序?看来你是对的,我错过了。另一个答案(你的)是正确的。
$sorted = array_multisort($utente, 'nome', SORT_ASC);
usort($utente, function($a, $b){
   if ($a->nome > $b->nome) {
      return 1;
   }elseif($a->nome < $b->nome){
      return -1;
   }else{
     return 0;
   }
});