April 11, 2018 —John Koster
The divide
helper method will take the given $array
and create two new arrays. The first array will be all of the keys from the original $array
and the second array will be all of the values.
The signature of the divide
method is:
1public static function divide(2 $array3);
The following examples demonstrate how to use the divide
method separate an array into its key and value components:
1use Illuminate\Support\Arr;2 3$myArray = [4 'animal' => 'Araripe Manakin',5 'plant' => 'Pineland Wild Petunia'6];7 8$myArray = Arr::divide($myArray);
The final result would be:
1array { 2 array { 3 "animal" 4 "plant" 5 } 6 array { 7 "Araripe Manakin" 8 "Pineland Wild Petunia" 9 }10}
array_divide
Helper FunctionThe array_divide
function is a shortcut to calling Arr::divide
. This function is declared in the global namespace.
∎
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.