php

Tecker.Yu

2 minute read

class Post
{
	public $title;
	public $published;
	public $auth;

	function __construct($title,$auth,$published)
	{
		$this->title = $title;
		$this->published = $published;
		$this->auth = $auth;
	}
}

$posts = [
	new Post('first','jm',true),
	new Post('second','vm',true),
	new Post('third','cm',true),
	new Post('fourth','em',false)

];
  1. array_filter 数组过滤器

可以写成闭包的形式,那样当数组被遍历的时候每一个元素就会执行该方法,将符合条件的元素return回来,然后就组成了新的数组,如果键的值为空,那么这个键将不会被保存在 新的数组里