Pattern Matching in PHP
Learn about pattern matching functionality in a functional-php library.
We'll cover the following...
Not to be confused with regular expression matching, pattern matching is a means of matching patterns against values. It’s rather straightforward. Pattern matching is immanent in the designs of languages like Haskell and Elm and is not organically supported in PHP. Among the mitigations of the innately absent pattern matching is the package aptly named functional-php/pattern-matching
, created and maintained by Gilles Crettenand. It allows the usage of pattern matching syntax similar to Haskell and also enables pattern value extraction.
Switch vs. pattern matching
The switch statement is a pervasive control structure and is often used to differentiate discernible selections. It’s used for flow control but is not expressive enough to accommodate ...