Creates an array by using one array for keys and another for its values – PHP

<?php
 $testArray1 = array('key1', 'key2', 'key3');
 $testArray2 = array('value1', 'value2', 'value3');
 $testArray3 = array_combine($testArray1, $testArray2);
 print_r($testArray3);
 //Array ( [key1] => value1 [key2] => value2 [key3] => value3 )
 //  NOTE : Make sure that the 2 arrays have  equual
 //  number of elements
?>

Leave a Reply

Your email address will not be published. Required fields are marked *