欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

类与in_array

程序员文章站 2022-05-25 18:36:09
...
test.php
<?php

class test{

private $name;
private $pas = 'ddd';
private $name1 = true;

function __construct($array1=array()){

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

if(!in_array($key,array_keys(get_class_vars(get_class($this))))){
continue;
}

$this->setOption($key,$value);
}

}

private function setOption($key,$value){
$this->$key = $value;
}


}

?>
index.php
<?php

require 'test.php';
$object = new test(array('name'=>'xuepeng11'));

var_dump($object);


?>

相关标签: PHP