本篇对php面向对象选择排序实例讲解。
<!--?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 '
';
}
}
}
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 '
';
print_r($selection);本篇讲解了php面向对象选择排序实例,更多相关内容请关注php中文网。
相关推荐:
立即学习“PHP免费学习笔记(深入)”;
以上就是php面向对象选择排序实例讲解的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号