The Blog

Laravel

Laravel

Collapsing Laravel Collections using array_collapse

John Koster
John Koster
November 18, 2016

Learn how to use the collapse method in Laravel's Illuminate\Support\Arr helper class to flatten arrays and collections. No special syntax is needed to use the collapse method with collections. Nested collections can also be collapsed. Find out how to implement this useful function in your Laravel projects.

Laravel

Laravel Array Helper Function: array_add

John Koster
John Koster
November 18, 2016

Learn how to use the add helper method to add key-value pairs to an array in PHP. This method checks if the key already exists in the given array, and if not, it adds the key-value pair. See an example of how to use the add method and its code snippet. Additionally, find out about the array_add function, which is a shortcut to calling Arr::add.

Laravel

Laravel Array Helper Function: array_build

John Koster
John Koster
November 18, 2016

Learn how to create a new array with key/value pairs that have been modified by a callback function using the $build helper method in PHP. The callback function should return an array with the new key and value. Check out the example provided to see how this method works and how it can be used to append "is rare" to the values in an array. Additionally, learn about the shortcut function array_build, which is declared in the global namespace and calls Arr::build.

Laravel

Laravel Array Helper Function: array_collapse

John Koster
John Koster
November 18, 2016

The collapse helper method in Laravel accepts an array as its parameter and returns a new array with the contents of all the nested arrays. The method is not recursive, meaning it only collapses the top-level arrays. There is also a global function called array_collapse which is a shortcut to calling Arr::collapse.

Laravel

Laravel Array Helper Function: array_divide

John Koster
John Koster
November 18, 2016

The divide helper method in Laravel's Arr class takes an array and splits it into two separate arrays: one containing the keys and the other containing the values. In the provided example, the $myArray is divided into two arrays: [animal, plant] and [Araripe Manakin, Pineland Wild Petunia]. Another way to achieve the same result is by using the global array_divide function, which is just a shortcut for calling Arr::divide.

Laravel

Laravel Array Helper Function: array_dot

John Koster
John Koster
November 18, 2016

Learn how to use the dot helper method in Laravel to convert a multi-dimensional array into an associative array with keys separated by periods. Find out how to use the dot method with and without a prefix. Additionally, discover the shortcut function array_dot that calls Arr::dot in the global namespace.

Laravel

Laravel Array Helper Function: array_except

John Koster
John Koster
November 18, 2016

The except helper method in Laravel allows you to retrieve key/value pairs from an array based on keys that are not included in another array. It simplifies the process of excluding specific keys when working with arrays. You can pass a single key or an array of keys to exclude. The array_except function is a shortcut to calling Arr::except and is available in the global namespace.

Laravel

Laravel Array Helper Function: array_fetch

John Koster
John Koster
November 18, 2016

Learn about the fetch helper function in Laravel, which has been deprecated in favor of the pluck helper function. This function allows you to retrieve data from a multi-dimensional array using dot notation. Check out the [An Extended Example of Retrieving Unique Data Using Laravel Helper Functions](/blog/2016/11/18/an-extended-example-of-retrieving-unique-data-using-laravel-helper-functions) article for more insights into Laravel's array helper functions.

Laravel

Laravel Array Helper Function: array_flatten

John Koster
John Koster
November 18, 2016

Learn how to flatten multi-dimensional arrays with the flatten helper method in PHP. While the dot method preserves keys using dots, the flatten method creates a new array without the original keys. Use array_flatten as a shortcut to Arr::flatten in the global namespace.

Laravel

Laravel Array Helper Function: array_only

John Koster
John Koster
November 18, 2016

Learn how to use the only helper method in Laravel to retrieve specific keys from an array. With the only method, you can easily extract the desired elements from an array by specifying the keys you want. This method is especially useful when working with large arrays and needing to retrieve only certain values. Check out this article to get a detailed explanation and example of the only helper method in action.

Latest posts

Where Things get Good: Moving on to Forte Development Phase 1

Wrapping up Forte Phase 0 with the lexer and parser now in private alpha, and kicking off Phase 1 wi...

Read more
Forte Update: Backtracking, Metadata, HTML Validation, and More

A Forte development update: the parser now supports backtracking, improvements to node metadata, ide...

Read more
Parsing HTML and Blade Attributes in Forte

Wrapping up attribute parsing in Forte's HTML parser, from simple HTML attributes to complex, edge-c...

Read more
Switch Statements and Parser Extensions in Forte

Exploring how Forte's parser extensions can be used to handle complex Blade directives like nested s...

Read more
Parsing Blade Comments in Forte

Digging into parsing Blade and HTML comments while building Forte's HTML parser for Laravel Blade.

Read more
Thoughts on HTML Elements and Blade Components in Forte

This week I’m tackling Forte's HTML parser - consolidating Blade, Flux, and Livewire components into...

Read more