3

I have 2 arrays

$arr1 = Array
(
    [0] => 12
    [1] => 4
    [2] => 8
    [3] => xx
    [4] => 1
    [5] => 1year
    [6] => 7
)
$arr2 = Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 6
    [6] => 7
)

I want to create a new array with the values of a2 as keys in $arr1. My resultant array should be like this

$arr3 = Array
(
    [1] => 12
    [2] => 4
    [3] => 8
    [4] => xx
    [5] => 1
    [6] => 1year
    [7] => 7
)
1
  • @Pekka how to array_combine($arr2, $arr1)? ;) Commented Jan 13, 2011 at 12:54

3 Answers 3

7
$arr3 = array_combine($arr2, $arr1);
print_r($arr3);

Next time please consult the manual first.

Sign up to request clarification or add additional context in comments.

Comments

4

You need array_combine.

Comments

0

whats about looking into php manual? and find array_combine($keys, $values)

1 Comment

You are very clever to snidely make your point by using a word that is not in the dictionary and a sentence that would make a grammar book curl its pages in horror ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.