English 中文(简体)
单列的Sort php阵列和列出的产出
原标题:Sort php array on one column and output to list
  • 时间:2009-10-15 05:56:10
  •  标签:

我创建了一个阵列,由一阵 lo组成:

<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>

        $alisting []["questions"] = $questions; 
        $alisting []["id"] = $post->ID; 
        $alisting []["title"] = $post->post_title; 

<?php endwhile; ?>

产出

Array ( [0] => Array ( [questions] => 22 ) [1] => Array ( [id] => 1016 ) [2] => Array ( [title] => Cash Commons ) [3] => Array ( [questions] => 15 ) [4] => Array ( [id] => 811 ) [5] => Array ( [title] => The Poker Echo ) [6] => Array ( [questions] => 34 ) [7] => Array ( [id] => 437 ) [8] => Array ( [title] => VideoWTF.com ) [9] => Array ( [questions] => 34 ) [10] => Array ( [id] => 295 )

我需要以问题分类,按顺序排列这一阵列,并把它列入一个名单,以便我有:

ID       | Title           |  Question

1023       Cash Commons       43
987        Videowtf           34

etc

如果有非常明确的指示,请人提供帮助。

事先得到你的帮助。

卡车

nathan

问题回答

http://www.php.net/manual/en/Function.uasort.php http://www.php.net/manual/en/Function.uasort.php,并创建一种召回功能。

function sort_callback($a, $b){
    if ($a[ Question ] == $b[ Question ]) {
        return 0;
    }
    return ($a[ Question ] < $b[ Question ]) ? 1 : -1;
}

uasort($alisting, sort_callback );

使用阵列:多





相关问题
热门标签