2015-07-22 3 views

ответ

0
// First, ensure they are the same length  
if(count($arr_1) == count($arr_2)){ 

    // Then combine them into associative array 
    $combined_array = array_combine($arr_1, $arr_2); 

    // Check the array is not empty 
    if(!empty($combined_array)){ 

    // Print them out (alternatively put them in an array) 
    foreach($combined_array as $key => $value){ 
     echo $key . ":" . $value . "<br>"; 
    } 
    } 
} 
1

Использование array_combine() для этого:

$arr_1 = array(a,b,c,d); 
$arr_2 = array(e,f,g,h); 
$result = array_combine($arr_1, $arr_2); 
2
<?php 

$arr_1 = array('a','b','c','d'); 
$arr_2 = array('e','f','g','h'); 

$array3 = array_combine($arr_1, $arr_2); 
foreach($array3 as $key=>$val){ 
echo $key.":".$val."<br>"; 
} 
Смежные вопросы