<?php
//Bean
class HumanBeans
{
private $name;
private $age;
public function setName($name){
$this->name = $name;
}
public function setAge($age){
$this->age = $age;
}
public function getName(){
return $this->name;
}
public function getAge(){
return $this->age;
}
}
//Dto
class HumDto
{
private $dtolist;
private $ageTotal;
private $ageAverage;
public function HumDto(){
}
//リストをsetしサイズを返す
public function listSet($dtolist){
$this->dtolist = $dtolist;
return count($this->dtolist);
}
//Ageの合計
public function ageTotal(){
for($i = 0 ; $i < count($this->dtolist) ; $i++){
$this->ageTotal += $this->dtolist[$i]->getAge();
}
return $this->ageTotal;
}
//Ageの平均を返す
public function ageAverage(){
$this->ageAverage = $this->ageTotal/count($this->dtolist);
return $this->ageAverage;
}
}
//Dao
class HumDao
{
//今回は$humをDBのデータと見立てて使います
public $hum = array(
0 => array('name' => 'ito' , 'age' => 9,),
1 => array('name' => 'suzuki' , 'age' => 21,),
2 => array('name' => 'tanaka' , 'age' => 33,)
);
public function HumDao(){
$humlist = array();
//print_r ($this->hum);//配列データ
$humdto = new HumDto();//Dto
echo "<br>";
for($i = 0 ;$i < count($this->hum) ; $i++){
$bean = new HumanBeans();
$bean->setName($this->hum[$i][name]);
$bean->setAge($this->hum[$i][age]);
$this->humlist[] = $bean ;
}
echo $humdto->listSet($this->humlist)."データサイズ<br>";//Dtosetデータサイズ
echo $humdto->ageTotal()."Ageの合計<br>";//Ageの合計
echo $humdto->ageAverage()."Ageの平均<br>";//Ageの平均
//var_dump($this->humlist);
for($i = 0 ; $i < count($this->humlist) ; $i++){
echo "名前:".$this->humlist[$i]->getName()." ";
echo "年齢:".$this->humlist[$i]->getAge()." ";
echo "<br>";
}
}
}
new HumDao();
//Bean
class HumanBeans
{
private $name;
private $age;
public function setName($name){
$this->name = $name;
}
public function setAge($age){
$this->age = $age;
}
public function getName(){
return $this->name;
}
public function getAge(){
return $this->age;
}
}
//Dto
class HumDto
{
private $dtolist;
private $ageTotal;
private $ageAverage;
public function HumDto(){
}
//リストをsetしサイズを返す
public function listSet($dtolist){
$this->dtolist = $dtolist;
return count($this->dtolist);
}
//Ageの合計
public function ageTotal(){
for($i = 0 ; $i < count($this->dtolist) ; $i++){
$this->ageTotal += $this->dtolist[$i]->getAge();
}
return $this->ageTotal;
}
//Ageの平均を返す
public function ageAverage(){
$this->ageAverage = $this->ageTotal/count($this->dtolist);
return $this->ageAverage;
}
}
//Dao
class HumDao
{
//今回は$humをDBのデータと見立てて使います
public $hum = array(
0 => array('name' => 'ito' , 'age' => 9,),
1 => array('name' => 'suzuki' , 'age' => 21,),
2 => array('name' => 'tanaka' , 'age' => 33,)
);
public function HumDao(){
$humlist = array();
//print_r ($this->hum);//配列データ
$humdto = new HumDto();//Dto
echo "<br>";
for($i = 0 ;$i < count($this->hum) ; $i++){
$bean = new HumanBeans();
$bean->setName($this->hum[$i][name]);
$bean->setAge($this->hum[$i][age]);
$this->humlist[] = $bean ;
}
echo $humdto->listSet($this->humlist)."データサイズ<br>";//Dtosetデータサイズ
echo $humdto->ageTotal()."Ageの合計<br>";//Ageの合計
echo $humdto->ageAverage()."Ageの平均<br>";//Ageの平均
//var_dump($this->humlist);
for($i = 0 ; $i < count($this->humlist) ; $i++){
echo "名前:".$this->humlist[$i]->getName()." ";
echo "年齢:".$this->humlist[$i]->getAge()." ";
echo "<br>";
}
}
}
new HumDao();
0 件のコメント:
コメントを投稿