1

I have 2 arrays , $array1 & $array2. I want to create new array such that its key value is values of array1 and values are values of array2. Is it possible..

I used following approach to create this new array named $inputs. Is this correct?

$inputs=array();
$array1=array("3","4","6");
$array2=array("a","b","c");
$inputs=array_fill("$array1",count($array1),$array2);
print_r($inputs);
1
  • Just test it. Additionally array_combine() is what you're looking for probably. Commented Jul 14, 2011 at 19:12

3 Answers 3

3

If I read your question correctly, you can use array_combine() PHP Manual

$array1 = array("3","4","6");
$array2 = array("a","b","c");
$inputs = array_combine($array2, $array1); # keys, values
Sign up to request clarification or add additional context in comments.

Comments

2

Use array_combine.

http://www.php.net/manual/de/function.array-combine.php

$inputs = array_combine($array1, $array2);

Comments

1
<?php
$inputs=array();
$array1=array("3","4","6");
$array2=array("a","b","c");
$inputs=array_combine($array1,$array2);
print_r($inputs);

?>

http://codepad.org/6fTXCZa5 use php array_combine function http://php.net/manual/en/function.array-combine.php

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.