PHP object-oriented selection sorting example explanation

jacklove
Release: 2023-03-27 13:32:01
Original
1576 people have browsed it

This article explains PHP object-oriented selection and sorting examples.

<!--?php
/**
 * Created by PhpStorm.
 * User: lzh
 * Date: 2018/2/10
 * Time: 下午10:50
 */
class selectionSortData {
    private $var = array();
 
    /**
     * selectionSortData constructor.
     * @param $in
     */
    public function __construct($in)
    {
        if (is_array($in)) {
            $this--->var = $in;
        }
        if (is_numeric($in)) {
            for ($count = 0; $count < $in; $count ++) {
                $random = mt_rand(1, 100);
                array_push($this->var, $random);
                print_r($this->var);
                echo &#39;
&#39;;
            }
        }
    }
 
    public function swap($left, $right) {
        $temp = $left;
        $left = $right;
        $right = $temp;
    }
 
    public function sort() {
        $temp = $this->var[0];
        for ($i = 0; $i < count($this->var); $i ++) {
            if ($this->var[$i] > $temp) {
                $this->swap($temp, $this->var[$i]);
            }
        }
        return $this->var;
    }
}
 
$selection = new selectionSortData(10);
        echo &#39;
&#39;;
        print_r($selection);
Copy after login

This article explains PHP object-oriented selection and sorting examples. For more related content, please pay attention to the PHP Chinese website.

Related recommendations:

PHP skills: skillfully use json_encode() to assign values ​​to js arrays

PHP and XML technology Features and syntax instructions

Explanation of PHP and Ajax technology

The above is the detailed content of PHP object-oriented selection sorting example explanation. For more information, please follow other related articles on the PHP Chinese website!

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!