首页 >社区问答列表 >使用类来对二维数组进行输出应该怎么做?

使用类来对二维数组进行输出应该怎么做?

<?php

class demo{

protected $name;

protected $age;

protected $wages;


public function __construct($name,$age,$wages){

$this->name = $name;

$this->age = $age;

$this->wages = $wages;


}

public function show(){

return "员工的姓名是:{$this->name} 年龄:{$this->age} 工资:{$this->wages}";

}

}


$obj = new demo('peter',24,5000);

echo $obj->show();

    echo '<br />';


$arr = array(array('name'=>'jike','age'=>18,'wages'=>'500'),

array('name'=>'jike','age'=>18,'wages'=>'500'),);

foreach ($arr as $key => $value) {

if(is_array($value)){

foreach ($value as $key => $v) {

echo $key.'-'.$v.'<br>';

}

}

}



?>


无数据提示还没有回复,楼主喊你快去抢前排~~~我来回答