Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP assign index of an array to another array

Tags:

arrays

php

$arr1 = array('001','002','003');
$arr2 = array('aaa','bbb','ccc');

//$result = join $arr1 and $arr2;

I want $result such that $arr1 value becomes index of $result and $arr2 become value of each index of $result. Final result should be

$result = array("001"=>"aaa","002"=>"bbb","003"=>"ccc");
like image 834
user713085 Avatar asked Dec 08 '25 23:12

user713085


1 Answers

Use array_combine. Example:

array_combine($keys,$values)

for your question

try

$result = array_combine($arr1,$arr2);
like image 184
diEcho Avatar answered Dec 11 '25 13:12

diEcho



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!