The Blog

Laravel

Laravel

Laravel Array Helper Function: array_pull

John Koster
John Koster
November 19, 2016

The pull helper method in Laravel is used to retrieve and remove a value from an array based on a specified key. It is similar to the get method, but with the additional functionality of removing the item from the array. This function is mutable and will affect the original array.

Laravel

Laravel Array Helper Function: array_set

John Koster
John Koster
November 19, 2016

The set helper method allows you to set values within an array using dot notation for the key. It is the opposite of the forget method. The set function mutates the original array and can be used to change the entire array or replace it with a different type. There is also a shortcut function called array_set available in the global namespace to call Arr::set.

Laravel

An Extended Example of Retrieving Unique Data Using Laravel Helper Functions

John Koster
John Koster
November 18, 2016

Learn how to use Laravel helper functions to retrieve a unique list of languages spoken by students. By flattening the array and using the array_unique function, you can easily get an array with all the unique languages.

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.

Latest posts

That Escalated Quickly: All the New Things

The past six months or so have been incredibly busy. What started as a new article series about cust...

Read more
Troubleshooting a Statamic Illegal Offset Type Error when Viewing Collection Entries in the Control Panel

In this post I talk about how I resolved a mysterious illegal offset type error when viewing collect...

Read more
Creating Simple HTTP Redirect Routes from a Statamic Site

Generating a custom Laravel routes file from a Statamic website to redirect to a new domain.

Read more
Disabling Vite File Hashes

Disabling file hashes in Vite output can be accomplished by modifying your project's vite.config.js

Read more
Implementing a Custom Laravel Blade Precompiler for Volt and Livewire

Learn how to implement a custom component compiler for Laravel's Blade templating language in this p...

Read more
Creating a Hybrid Cache System for Statamic: Part Five

Part 5 of 6 covers implementing a cache namespace and labeling system, which we can use to target mu...

Read more