-2

如何显示包含数组的地址的内容?

例子:

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
4

1 回答 1

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();
于 2013-03-06T17:17:41.580 回答