Home >Backend Development >PHP Problem >How to implement batch change function in php
php method to implement the batch change function: first create a PHP sample file; then use the "public function refresh(){...}" method to implement the batch change function.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
How does php realize the function of changing batches?
php realizes the change function
public function refresh() { /*换一换功能实现 查找前20条数据的id值 组成一维数组 在一维数组中再进行随机得到10个键名 得到含有随机键名的一维数组 循环遍历 得到含有随机id得数据 然后进行查找得到数据 */ //第一步:得到的首页显示六本默认图书 $index_book = $this->Model_book->get_index_book2(20); $rand=array_rand($index_book,9); $book=array(); foreach($rand as $k=>$v){ $book[$k]=$index_book[$v]; } if(count($book)>0){ echo json_encode($book); }else{ echo ''; } }
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to implement batch change function in php. For more information, please follow other related articles on the PHP Chinese website!