Search Results: Found 2
The Dual Nature of PHP's `array_column`: Why It Seamlessly Handles Both Arrays and Active Record Objects
2026-02-09 DP

Discover a powerful feature of PHP's built-in `array_column` function: its ability to process both traditional associative arrays and collections of Active Record objects without any code changes. This article delves into its internal mechanics and demonstrates its flexibility and convenience in real-world development with code examples.

The Magic of PHP Enums: Elegantly Convert an Enum to a Key-Value Array with One Line of Code
2025-12-16 DP

How do you dynamically get all statuses of a model in modern PHP development? This article provides an in-depth analysis of an elegant PHP snippet that leverages PHP 8.1+ Enums, interfaces, and the `array_column` function to free status definitions from being hardcoded. You will learn how the clever combination of `Enum::cases()` and `array_column` can convert an enum into a `['STATUS_NAME' => status_value]` associative array in a single line, and understand the principles behind it.