Courses

PHP for Laravel Developers

Popular Array Functions: Open-Source Examples

Summary of this lesson:
- Learn about common PHP array manipulation functions
- Understand array checking and filtering techniques
- Explore practical uses of array functions
- Examine methods for array transformation

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 16 lessons of this course? (52 min read)

You also get:

  • 73 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord