Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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_Wordpress_Sorting_Multidimensional Array - Fatal编程技术网

Php 按值对多维数组排序?

Php 按值对多维数组排序?,php,arrays,wordpress,sorting,multidimensional-array,Php,Arrays,Wordpress,Sorting,Multidimensional Array,您好,我将尝试多排序数组,显示数组列表的基础上最近的职位价值,我需要订单列表,请找到我的代码和帮助我们 <?php $data = array(); $i = 0; while($loop->have_posts()) : $loop->the_post(); $title = get_the_title(); $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_

您好,我将尝试多排序数组,显示数组列表的基础上最近的职位价值,我需要订单列表,请找到我的代码和帮助我们

<?php
 $data = array();
    $i = 0;
    while($loop->have_posts()) : $loop->the_post();
    $title = get_the_title();
    $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'small');
    $comments_count = wp_count_comments(get_the_ID ());
    $comments_count = $comments_count->total_comments;

    ?>
        <div class="load_more" style="color:red;">
            <?php $row_id =  echo_views($id);
            $data[$i]['id'] = $row_id;
            $data[$i]['title'] = $title;
            $data[$i]['image'] = $large_image_url;
            $data[$i]['comments'] = $comments_count;            
            ?>
        </div>
    <?php    
    $i++;
    endwhile;
echo '<pre>';print_r($data);
?>
我需要结果(使用升序列表筛选[id]:


使用usort对数组进行排序。你可以查一下电话号码


使用数组\u多重排序数组

array\u multisortarray\u column函数可用于使用键对多维数组进行排序,该键在示例中为ID。array\u column函数用于指定用作排序顺序的键

语法:

array_multisort(array_column($data,'id'),SORT_ASC,$data);
解决方案:


在php7中可以使用飞船操作员的答案来解决您的问题。
Array
(
    [0] => Array
        (
            [id] => 127
            [title] => test2
            [image] => Array
                (                    
                )
            [comments] => 0
        )

    [1] => Array
        (
            [id] => 124
            [title] => test2
            [image] => Array
                (                    
                )
            [comments] => 0
        )

    [2] => Array
        (
            [id] => 116
            [title] => test3
            [image] => Array
                (                    
                )
            [comments] => 0
        )
)
usort($array, function($a, $b){return $b['id'] - $a['id'];});
array_multisort(array_column(array_name,key_name),SORT_DESC/SORT_ASC,array_name);
array_multisort(array_column($data,'id'),SORT_ASC,$data);