小编Bil*_*rer的帖子

学习php oop - 无法反转数组

我正在学习PHP OOP,我试图理解为什么以下脚本不起作用:

class ShowTimeline {
    var $conn;
    var $rev;

    function getTimeline ($conn) {
        return $this->conn;
    }

    function reverseTimeline () {
        $rev = array_reverse($this->conn, false);
        return $rev;
    }

    function display () {
        $this->reverseTimeline();
        print_r($this->rev);
    }
}
print '<hr />';
$connect = new showTimeline();
$connect->conn = array('one', 'two', 'three');
$connect->display();
Run Code Online (Sandbox Code Playgroud)

当我将脚本更改为:

//same stuff above
function display () {
            $this->reverseTimeline();
            print_r($this->conn); //changed from $this->rev
        }
//same stuff below
Run Code Online (Sandbox Code Playgroud)

我打印出来了:

Array ( [0] => one [1] => two [2] => three )
Run Code Online (Sandbox Code Playgroud)

哪个是对的.请帮忙?

php oop

1
推荐指数
1
解决办法
193
查看次数

标签 统计

oop ×1

php ×1