Showing 7 of 1,216 result(s)
The signature of the get method is:
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...
The array_get function is a shortcut to calling Arr::get . This function is declared in the global namespace.
The signature of the pluck method is:
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...
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...
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...