All for Joomla The Word of Web Design

Laravel Arrays & Objects helper

custom 404 page laravel

Laravel is a PHP MVC framework that boosts up the development process with its friendly and simple syntax pattern, artisan, route,database migration and schema builder tools, simple and secure authentication mechanism, and much more. This is what makes Laravel the best PHP framework.
laravel also provide many useful functions and classes. Today we will discuss few of laravel helper functions and methods

These methods are given below:

1. array_add( )

The array_add function adds a given key / value pair to an array if the given key doesn’t already exist in the array:

2. array_collapse( )

The array_collapse function collapses an array of arrays into a single array:

3. array_divide( )

The array_divide function returns two arrays, one containing the keys, and the other containing the values of the given array:

4. array_dot( )

The array_dot function flattens a multi-dimensional array into a single level array that uses “dot” notation to indicate depth:

5. array_except( )

The array_except function removes the given key / value pairs from an array:

6. array_first( )

The array_first function returns the first element of an array passing a given truth test:

A default value may also be passed as the third parameter to the method. This value will be returned if no value passes the truth test:

7. array_flatten()

The array_flatten function flattens a multi-dimensional array into a single level array:

8. array_forget( )

The array_forget function removes a given key / value pair from a deeply nested array using “dot” notation:

9. array_get( )

The array_get function retrieves a value from a deeply nested array using “dot” notation:

The array_get function also accepts a default value, which will be returned if the specific key is not found:

10. array_has( )

The array_has function checks whether a given item or items exists in an array using “dot” notation:

11. array_last( )

The array_last function returns the last element of an array passing a given truth test:

A default value may be passed as the third argument to the method. This value will be returned if no value passes the truth test:

12. array_only( )

The array_only function returns only the specified key / value pairs from the given array:

13. array_pluck( )

The array_pluck function retrieves all of the values for a given key from an array:

You may also specify how you wish the resulting list to be keyed:

14. array_prepend( )

The array_prepend function will push an item onto the beginning of an array:

If needed, you may specify the key that should be used for the value:

15. array_pull( )

The array_pull function returns and removes a key / value pair from an array:

A default value may be passed as the third argument to the method. This value will be returned if the key doesn’t exist:

16. array_random( )

The array_random function returns a random value from an array:

You may also specify the number of items to return as an optional second argument. Note that providing this argument will return an array, even if only one item is desired:

17. array_set( )

The array_set function sets a value within a deeply nested array using “dot” notation:

18. array_sort( )

The array_sort function sorts an array by its values:

You may also sort the array by the results of the given Closure:

19. array_sort_recursive()

The array_sort_recursive function recursively sorts an array using the sort function:

20. array_where( )

The array_where function filters an array using the given Closure:

21. array_wrap( )

The array_wrap function wraps the given value in an array. If the given value is already an array it will not be changed:

22. data_fill( )

The data_fill function sets a missing value within a nested array or object using “dot” notation:

This function also accepts asterisks as wildcards and will fill the target accordingly:

23. data_get( )

The data_get function retrieves a value from a nested array or object using “dot” notation:

The data_get function also accepts a default value, which will be returned if the specified key is not found:

24. data_set( )

The data_set function sets a value within a nested array or object using “dot” notation:

This function also accepts wildcards and will set values on the target accordingly:

By default, any existing values are overwritten. If you wish to only set a value if it doesn’t exist, you may pass false as the third argument:

25. head( )

The head function returns the first element in the given array:

26. last( )

The last function returns the last element in the given array:

These are few helper function of the laravel, these are very useful and helpful to boost up your development speed.

Source : laravel docs

Thanks, I hope this post will help you.

1 Comment

Leave a Comment

Login

Welcome! Login in to your account

Remember me Lost your password?

Lost Password