Search

The blog - interstellar.

Laravel Array Helper Function: array_add

Nov 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 Array Helper Function: array_build

Nov 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 Array Helper Function: array_collapse

Nov 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 Array Helper Function: array_divide

Nov 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 Array Helper Function: array_dot

Nov 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 Array Helper Function: array_except

Nov 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 Array Helper Function: array_fetch

Nov 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 Array Helper Function: array_flatten

Nov 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 Array Helper Function: array_only

Nov 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.
Laravel Array Helper Functions

Nov 18, 2016

Learn about Laravel's array helper functions and how they provide additional functionality on top of PHP's built-in array functions. These functions are located within the Illuminate\Support\Arr class and treat arrays as immutable data structures. See an example of how changes made to an array are returned as a copy of the original array, with the original array remaining unchanged. Discover how Laravel's helper functions support "dot" notation when accessing items in an array, similar to JavaScript's dot notation for accessing object properties.
Laravel Helper Function: ASCII

Nov 16, 2016

The ascii helper method in Laravel converts a UTF-8 encoded string into its ASCII equivalent. It accepts a single argument, which should be a string or something that can be cast into a string. This function is useful when communicating with other software platforms that require ASCII, or when complying with protocols like HTTP. In Laravel 5, the ascii function uses the stringy library, while previous versions of Laravel used the patchwork/utf8 package.
Laravel String Helper Function: studly_case

Nov 16, 2016

Studly caps is a formatting style for text that involves capitalizing the first letter of each word while removing certain word separators. Laravel provides a Str::studly method to implement this formatting. Examples include transforming "my words" to "MyWords" and "my-WORDS" to "MyWORDS". Pascal case, which is similar to camel case with the first letter capitalized, can also be achieved with studly. There is also a global function studly_case available as a shortcut to Str::studly.
Laravel Security Helper Function: e for HTML Entities

Nov 16, 2016

Learn how to use the e function in PHP to sanitize user input and prevent potential security vulnerabilities. The e function is a convenient wrapper for PHP's htmlentities function and utilizes the UTF-8 character encoding. By using the e function, you can safely display user input in the browser without the risk of executing malicious code. Discover how to implement the e function and ensure that the browser renders user input as intended.
Laravel String Helper Function: camel

Nov 16, 2016

Learn how to use the camel helper function in Laravel's Illuminate\Support\Str class to convert strings to camel case. Discover examples of how to convert various forms of strings to camel case, and understand that the function only affects the casings of the first character. Additionally, find out about the convenient camel_case function, which is a shortcut to calling Str::camel.

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.