?php //array_map() 可以使用用户自定义的函数对数组中的每个元素做回调处理 成功返回true, 失败返回false $fruits =array('a'='apple','b'='banana','o'='ornge','1'='lemon'); $fav='orange'; function test($item,$key,
-
<?php -
//array_map() 可以使用用户自定义的函数对数组中的每个元素做回调处理 成功返回true, 失败返回false -
$fruits =array('a'=>'apple','b'=>'banana','o'=>'ornge','1'=>'lemon'); -
$fav='orange'; -
function test(&$item,$key,$prefix){ -
$item="$prefix:$key=>$item"; -
} -
array_walk($fruits,'test','fruit'); -
echo '<pre>'; -
print_r($fruits); -
//arraya_map(callback,arr1,arr2 。。。) -
$arr = array_map(function($v){ -
if($v>25) return $v; -
},[25,12,521,58,556]); -
echo '<pre>'; -
print_r($arr); -
//使用array_filter()使用回调函数过滤数组的元素 返回是过滤后的数组 -
/*$arr=array_filter($arr); -
print_r($arr);*/ -
//array_values()给数组的键重新排序,从0递增 -
var_dump($arr =array_values(array_filter($arr))); -
ob_clean(); -
$a=[25,12,521,58,556]; -
$res=array_values( array_filter($a,function($b){ -
return $b>25; -
})); -
echo '<pre>'; -
print_r($res); -
<?php -
/* -
* 1.变量 实现数据的复用 函数是实现代码块的复用 -
* 2.类是具有相同属性和方法的对象的集合 -
* 3.对象是复合数据类型 -
* 4.oop三大特性 封装 继承 多态 -
* //封装:隐藏对象的属性或方法(实现细节),目的是为了控制在程序中属性的读或者修改的访问级别,使用者只需要通过外部接口 以特定的权限来使用类成员 -
* -
* */ -
class Player{ -
//成员属性 前一定要有访问修饰符 public protected private -
public $name; //抽象属性 null -
public $height; -
public $team; -
//protected 只能被本类和子类访问 -
protected $playNum=23; -
private $weight; -
public function jog(){ -
return "$this->name is jogging,whose playNum is $this->playNum<br>"; -
} -
public function shoot(){ -
return "$this->name is shooting weighing $this->height"; } -
//__construct -
public function __construct($name,$height,$team,$playNum,$weight){ -
$this->name=$name; -
$this->height=$height; -
$this->team=$team; -
$this->playNum=$playNum; -
$this->weight=$weight; -
} -
} -
//类的实例化 new $j对象引用 -
/* $jordan=new Player; -
$james=new Player; -
对象成员的访问 对象引用 -》属性名称/方法名称() -
$jordan->name ='Jordan'; -
$james ->name ='James'; -
echo $jordan->name.'<br>'; -
echo $jordan->jog(); -
echo $james->name.'<br>'; -
echo $james->jog();*/ -
$jordan = new Player('Jordan','203cm','bulk',23,'80KG'); -
echo $jordan->name.'<br>'; -
echo $jordan->shoot(); -
<?php -
//客户端代码 调用封装的类 -
//1.加载类文件 -
//require '5.php'; -
//类的自动加载 -
spl_autoload_register(function($className){ -
require $className.'.php'; -
}); -
//2.new类的实例化 -
$j= new User('Jordan','203CM','Bulk',23,'80kg'); -
echo $j->shoot();
