I was following a tutorial and came across this,let's say I'm having an array of posts(objects) having two properties:
title of the post and the status (is it published or not).
and in my code I want to return those posts who are not published yet.
I know there are various ways to do that but in the tutorial the code shown was like this
$posts = [
new Post("My First Post",false),
new Post("My Second Post",true),
new Post("My Third Post",false),
new Post("My Fourth Post",false),
new Post("My Fifth Post",true),
];
$unpulishedPost = array_filter( $posts,function ($post){
return !$post->published;
});
I can't get my head around how does return actually returns the entire post object when it should only returns an array of booleans shouldn't the code be like so
$unpulishedPost = array_filter( $posts,function ($post){
if(!$post->published)
return $post;
});