array_combine仅返回最后一个值 [英] array_combine is return only last value
本文介绍了array_combine仅返回最后一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于foreach loop
,我有两个不同的array
,所以我决定将它们组合并一起运行到foreach loop
,但是它只返回数组的最后一个值.
I have two different array
for foreach loop
so i decide to combine them and run in to foreach loop
together but it's returning only last value of array.
数组1:$FileType
Array 1: $FileType
Array
(
[0] => image/png
[1] => image/png
[2] => image/png
[3] => image/png
[4] => image/png
[5] => image/png
)
阵列2:$FileName
Array 2: $FileName
Array
(
[0] => post2.png
[1] => post5.png
[2] => post6.png
[3] => post7.png
[4] => post8.png
[5] => post11.png
)
这是我的代码:
foreach(array_combine($FileType,$FileName) as $Type => $Name){
echo $Type .":". $Name;
}
仅返回最后一个值
返回:
image/png:post11.png
推荐答案
array_combine 并非如此.
您可以轻松完成
foreach($FileName as $id=>$Name)
{
echo $FileType[$id] .":". $Name;
}
假设两个数组的大小和键都相同
Assuming both arrays are of same size and same keys
这篇关于array_combine仅返回最后一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文