我得到了以下O/P在PHP如何分配特定阵列键的主阵列
$test1=["12","54","87","98"];
$test2=["1","5","8","9"];
在这如何可以在连接上述两个变量的一个变量像下面
1是12的键, 5是54键, 8是87键, 9是98键,
我得到了以下O/P在PHP如何分配特定阵列键的主阵列
$test1=["12","54","87","98"];
$test2=["1","5","8","9"];
在这如何可以在连接上述两个变量的一个变量像下面
1是12的键, 5是54键, 8是87键, 9是98键,
尝试这种情况:
$test1=["12","54","87","98"];
$test2=["1","5","8","9"];
$a = array_combine($test2, $test1);
echo "<pre>";
print_r($a);
exit;
希望这会有所帮助。
和平!的xD
谢谢你,亲爱的,它工作好 – KarnaGowtham
你可以试试这个
$test1=["12","54","87","98"];
$test2=["1","5","8","9"];
$new_array = array();
$i = 0;
foreach($test2 as $key=> $value)
{
$new_array[$value] = $test1[$i];
$i++;
}
echo '<pre>';
print_r($new_array);
array_combine最好亲爱的 – KarnaGowtham
我这么认为是因为它内置的功能。@ KarnaGowtham –
好吧好吧亲爱的,我找出解决方案 – KarnaGowtham
使用'array_combine()'。 – Yash
['array array_combine(array $ keys,array $ values)'](http://php.net/manual/en/function.array-combine.php) – Sean
谢谢你,亲爱的,它正在工作 – KarnaGowtham