如何显示包含数组的地址的内容?
示例:
class ConferenceInfo {
var $confID;
var $confName;
var $divisons = array();
/* display an address in HTML */
function display() {
$output = '';
$output .= $this->confID;
$output .= $this->confName;
foreach($this->divisons as $value) { // I know this is incorrect
$output .= $value;
}
$output .= '<br/>';
return $output;
}
}
PHP代码:
$conf = new ConferenceInfo;
$conf->confID = $someValue1;
$conf->confName = $someValue2;
$conf->divisons[] = $someValue3; // this will eventually loop and fill in multiple values
echo $conf->display();
数据示例如下:
confID = 1<br/>
confName = Eastern<br/>
dvisions = Atlantic, Central, Northeast
display()
的预期输出为:
1EasternAtlanticCentralNortheast
答案 0 :(得分:1)
class ConferenceInfo {
var $confID;
var $confName;
var $divisons = array();
/* display an address in HTML */
function display() {
$output = '';
$output .= $this->confID;
$output .= $this->confName;
foreach($this->divisons as $value) {
$output .= $value;
}
$output .= '<br/>';
return $output;
}
}
$conf = new ConferenceInfo;
$conf->confID = 1;
$conf->confName = "Eastern";
$conf->divisons = array("Atlantic", "Central", "Northeast");
echo $conf->display();