Tutorial by Examples

$fruit1 = ['apples', 'pears']; $fruit2 = ['bananas', 'oranges']; $all_of_fruits = array_merge($fruit1, $fruit2); // now value of $all_of_fruits is [0 => 'apples', 1 => 'pears', 2 => 'bananas', 3 => 'oranges'] Note that array_merge will change numeric indexes, but overwrite string...
The array_intersect function will return an array of values that exist in all arrays that were passed to this function. $array_one = ['one', 'two', 'three']; $array_two = ['two', 'three', 'four']; $array_three = ['two', 'three']; $intersect = array_intersect($array_one, $array_two, $array_thre...
The following example shows how to merge two arrays into one associative array, where the key values will be the items of the first array, and the values will be from the second: $array_one = ['key1', 'key2', 'key3']; $array_two = ['value1', 'value2', 'value3']; $array_three = array_combine($ar...
If you have a multidimensional array like this: [ ['foo', 'bar'], ['fizz', 'buzz'], ] And you want to change it to an associative array like this: [ 'foo' => 'bar', 'fizz' => 'buzz', ] You can use this code: $multidimensionalArray = [ ['foo', 'bar'], ...

Page 1 of 1