Skip to main content

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? (30 h 21 min)

You also get:

55 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…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.