gpt4 book ai didi

php - 如何在 PHP 类中定义数组属性

转载 作者:行者123 更新时间:2023-12-04 02:28:22 25 4
gpt4 key购买 nike

<分区>

我有以下简单代码,但它在 this->players[] = 'Tom' 行产生语法错误:

    <?php

class club {
var $clubID = 0;
var $players=array();

function __constructor($clubID = '') {
$this->clubID = $clubID;
}

function populatePlayers() {
$this->players[] = 'Tom';
}
}

$myClub = new club(1);
$myClub->populatePlayers();
var_dump($myClub->players);
?>

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com