Heim > Artikel > Backend-Entwicklung > php封装的有关问题
php封装的问题
[code=PHP][/code]
定义了一个User类
class User{
private $arr;//进行封装不让外部使用
function __construct(){
$this->arr = $this->get_data();//构造函数,在类一实例化的时候就会执行
}
public function isNotExist(){
echo "Does not exist
";
echo "重新输入";
}
private function get_data(){
$arr=array(
array("name"=>"张三","age"=>12,"sex"=>"男"),
array("name"=>"李四","age"=>25,"sex"=>"男"),
array("name"=>"王五","age"=>18,"sex"=>"男"),
array("name"=>"李利","age"=>16,"sex"=>"女"),
array("name"=>"陈明","age"=>25,"sex"=>"男"),
array("name"=>"张晓","age"=>25,"sex"=>"女"),
array("name"=>"李明","age"=>15,"sex"=>"男"),
array("name"=>"赵亮","age"=>25,"sex"=>"男"),
array("name"=>"张月","age"=>22,"sex"=>"男"),
array("name"=>"王青","age"=>21,"sex"=>"女")
);
return $arr;
}
public function joinHtml($array){
if(count($array)==0){
User::isNotExist();
}
$d = 0;
$b ="
".$d." | ".$t['name']." | ".$t['age']." | ".$t['sex']." |