PHP Array Combine
Last Updated on Feb 14, 2023
Array combine is another useful array function that creates an array by using one array for keys and another for its values.
The first argument is the array of keys and the second argument is the array of values.
The size of keys and values should be the same otherwise you will get an error.
the first item in the first array becomes the key to the first item of the second array and so on.
Let’s see an example
$keys = ['twitter', 'feedhive', 'php']; $values = ['pratham', 'simon', 'amir']; $combined = array_combine($keys, $values); print_r($combined); // Array ( // [twitter] => pratham // [feedhive] => simon // [php] => amir // )
Now you know about array combine in PHP.
I recommend you to open a PHP files define 2 arrays one for keys and one for values. then try to combine them together as one array.
If you have any suggestions, questions, or opinions, please contact me. I’m looking forward to hearing from you!
- array combine in php