PHP - Merge two arrays (same-length) into one associative? PHP - Merge two arrays (same-length) into one associative? arrays arrays

PHP - Merge two arrays (same-length) into one associative?


you need array_combine.

<?php$a = array('green', 'red', 'yellow');$b = array('avocado', 'apple', 'banana');$c = array_combine($a, $b);print_r($c);?>


There’s already an array_combine function:

$combined = array_combine($keys, $values);