Search

Showing 7 of 1,216 result(s)

/blog/2018/04/11/laravel-5-retrieving-elements-from-an-array-with-get#content-example-use

Assuming the following array: We can quickly retrieve the value for key like so: Where the alternative syntax would be: While PHP's array access syntax may be a little shorter, using dot notation is easier to read. We can also specify a $default...

/blog/2018/04/11/laravel-5-retrieving-elements-from-an-array-with-get#content-global-arrayget-helper-function

The array_get function is a shortcut to calling Arr::get . This function is declared in the global namespace.

/blog/2018/04/11/laravel-5-retrieving-nested-array-values-with-pluck#content-example-use

Let's use the following class to describe a person: We can create an array of people like so: At this point all we have is a simple Person class definition an array of person objects, called $people . However, it would be really useful if we had...

/blog/2018/04/11/laravel-5-retrieving-nested-array-values-with-pluck#content-returning-an-array-with-a-keyvalue-pair

We can also instruct the pluck method to return an array that contains both a key and a value. We do this by passing in a third argument to the pluck function: the $key . Let's reuse the people array: We can get an array with everyone's firstName...

/blog/2018/04/11/laravel-5-retrieving-nested-array-values-with-pluck#content-working-with-nested-arrays-or-objects

The $key supports dot notation, which implies that we can search for keys at arbitrary depths when constructing the final array. Let's add a new Job class, which will just be a very simple representation of a job: Now we will modify our Person...