类定义中不能直接包含代码。如果您想将其实例化,请将其放入__construct
作用
另外,请注意您缺少分号,并且.=
用于附加到字符串,而不是添加到数组。我也解决了这些问题:
<?php
class myclass {
private $arr = array(
\'emails\' => array(
\'[email protected]\',
\'[email protected]\',
\'[email protected]\'
)
);
protected $emails = array();
function __construct() {
foreach($this->arr[\'emails\'] as $email) {
$emails[] = $email;
}
}
}