Home > Backend Development > PHP Tutorial > thinkphp随机有关问题

thinkphp随机有关问题

WBOY
Release: 2016-06-13 12:06:21
Original
954 people have browsed it

thinkphp随机问题
比如卖出10条新闻,10条新闻做了排序了:1、2、3、4、5、5、5、6、6、7;
当遇到相同排序号时显示随机显示。也就是相同排序号局部随机显示。
这个东西不知道怎么写了;能不能实现?
------解决思路----------------------

$arr = array( <br />array('id' => 1,'name' => 'aaa','uid'=>1), <br />array('id' => 2,'name' => 'bbb','uid'=>2), <br />array('id' => 3,'name' => 'ccc','uid'=>3), <br />array('id' => 4,'name' => 'ddd','uid'=>4), <br />array('id' => 5,'name' => 'ccc','uid'=>4), <br />array('id' => 6,'name' => 'bbb','uid'=>4), <br />array('id' => 7,'name' => 'bbb','uid'=>5), <br />array('id' => 8,'name' => 'fff','uid'=>6), <br />array('id' => 9,'name' => 'ccc','uid'=>7), <br />array('id' => 10,'name' => 'bbb','uid'=>8), <br />array('id' => 11,'name' => 'ddd','uid'=>8), <br />array('id' => 12,'name' => 'eee','uid'=>9), <br />array('id' => 13,'name' => 'fff','uid'=>10), <br />); <br />usort($arr, function($a, $b) {<br />  if($a['uid'] == $b['uid']) return rand(-1, 1);<br />  return $a['uid'] > $b['uid'] ? 1 : -1;<br />  });<br />print_r($arr);
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