0

Ok, I have removed my php code which wasn't ok and rephrase what I'm looking for. Here I go...

Can I combine two arrays in 1 associative array?

$a = array("11", "22", "111");
$b = array("50", "30", "20");

I want both arrays to be combined in a new associative array as folows:

$appended = array ("11" => "50", "22" => "30", "111" => "20");

So, what I want to do is put the key from variable "$a" and the value from variable "$b"...

4
  • You are vulnerable to sql injection attacks Commented Mar 14, 2016 at 17:45
  • I think it might be an idea to throw away this code and start over. Forget about the PHP for the time being. Instead, consider following this simple two-step course of action: 1. If you have not already done so, provide proper DDLs (and/or an sqlfiddle) so that we can more easily replicate the problem. 2. If you have not already done so, provide a desired result set that corresponds with the information provided in step 1. Commented Mar 14, 2016 at 17:47
  • Are you talking about this? Merge two arrays (same-length) into one associative? You know the search won't bite or take a piece of you away, just give it a try :)! You waited 5 hours for something you would have spent less than 5 minutes to find :P Commented Mar 14, 2016 at 22:59
  • I was just reading the topic when you answered prix, coïncidence... My original post was relatively different though, hence the 5 hours... Commented Mar 14, 2016 at 23:13

1 Answer 1

0

Try the array_combine function:

$appended = array_combine($a, $b);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Zsolt, you won the prize as being the only one who answered 100% on-topic on my question! I almost got the impression that asking questions here is a dangerous undertaking...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.