我有两个阵列:
$arr_1 = array('a','b','c','d');
$arr_2 = array('e','f','g','h');
现在我想以下列格式获取值:
a:e
b:f
c:g
d:h
我该怎么做?谢谢!
答案 0 :(得分: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>";
}
答案 1 :(得分:1)
$arr_1 = array(a,b,c,d);
$arr_2 = array(e,f,g,h);
$result = array_combine($arr_1, $arr_2);
答案 2 :(得分: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>";
}
}
}