一个数组按照另一个数组元素顺序排序

WBOY
Release: 2016-06-06 20:07:26
Original
2816 people have browsed it

文字总是那么的苍白,上图
一个数组按照另一个数组元素顺序排序

第一个数组是拿到的id数组,且已经是排序好的
但是下面拿到的数据键值顺序已经乱了。在不使用foreach的情况下如何优雅的进行排序,结果和第一个数组顺序一样
想要得到的结果类似这样

<code class="php">    [
        131 => array(),
        89 => array(),
        141 => array(),
        43 => array(),
        140 => array(),
    ]</code>
Copy after login
Copy after login

回复内容:

文字总是那么的苍白,上图
一个数组按照另一个数组元素顺序排序

第一个数组是拿到的id数组,且已经是排序好的
但是下面拿到的数据键值顺序已经乱了。在不使用foreach的情况下如何优雅的进行排序,结果和第一个数组顺序一样
想要得到的结果类似这样

<code class="php">    [
        131 => array(),
        89 => array(),
        141 => array(),
        43 => array(),
        140 => array(),
    ]</code>
Copy after login
Copy after login

用foreach不是很好吗,再说view里面不就是用foreach遍历么?你可以不处理的。例

<code>$this->view->assign('indexArray', $indexArray);
$this->view->assign('dataArray', $dataArray);
//--view
foreach ($indexArray as $id) {
    print_r($dataArray[$id]); //对不对?
}</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!