Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Popular Array Functions: Open-Source Examples

Premium
5 min read

Arrays in PHP are used very widely. There are many functions for working with arrays. Let's check some of them and how they are used in Laravel open-source projects.


Example 1. is_array() and count()

One of the functions used often is checking if a variable is an array. In this example from Filament, first, it is checked if $state is an array, and if it is, then counts all elements in an array.

public function getItemsCount(): int
{
$state = $this->getState();
 
return is_array($state) ? count($state) : 0;
}

Link to the example in GitHub repository.


Example 2. array_merge() and array_filter()

A common situation is to merge arrays into one. Another situation is to...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

No comments yet…