PHP合并相应键中的数值数组的值

So consider an array with my 3 favorite fruits:

$array1 = array("Apple", "Banana","Raspberry")

I want to merge it with their own beautiful and natural color

$array2 = array("Green ", "Yellow ","Red ")

So that the results would look like

([0] => Green Apple [1] => Yellow Banane [2] => Red Raspberry) 

I need something to be scalable (2 to 6 keys, always the same between arrays)

What I tried and results

  • array_combine($array2,$array1)

    Result: Array ( [Green ] => Apple [Yellow ] => Banana [Red ] => Raspberry )

  • array_merge($array2,$array1)
    Result: Array ( [0] => Green [1] => Yellow [2] => Red [3] => Apple [4] => Banana [5] => Raspberry )

  • array_merge_recursive($array2,$array1)
    Result: Array ( [0] => Green [1] => Yellow [2] => Red [3] => Apple [4] => Banana [5] => Raspberry )

查看全部
doucheng3811
doucheng3811
2013/01/06 05:18
  • php
  • arrays
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复