Home > Backend Development > PHP Problem > How to implement batch change function in php

How to implement batch change function in php

藏色散人
Release: 2023-03-10 12:16:01
Original
1923 people have browsed it

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.

How to implement batch change function in php

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 '';
        }
    }
Copy after login

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!

Related labels:
php
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