1

I have two arrays the first one has this structure

Parameter Keys array

 array
   0 => 
    array
    0 => string ':user_pass' (length=10)
    1 => string ':user_id' (length=8)
    2 => string ':user_name' (length=10)
  1 => 
   array
    0 => string 'user_pass' (length=9)
    1 => string 'user_id' (length=7)
    2 => string 'user_name' (length=9)

The second is

 array
  0 => string 'test' (length=4)
  1 => string 'test' (length=4)
  2 => string '1' (length=1)

I want a new array with keys the same as the values from the first array[0][x], and then values the same as the values from the second array so I get something like for my new array

 array
  :user_id => string '1' (length=1)
  :user_name => string 'test' (length=4)
  :user_pass => string 'test' (length=4)

I tried using array combine but it needs the same amount of values and keys.

I just like to say the first array is created from a preg_match_all function

2 Answers 2

2

array_combine() is your answer.

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

2 Comments

Sorry I meant to say I used array combine but it needs the same amount of keys and values.
This answer isn't terribly generous.
1

The way you have it, your keys and values wouldn't match up:

<?php
$keys = array(
    array(':user_pass', ':user_id', ':user_name'),
    array( 'user_pass',  'user_id',  'user_name')
);

$values = array('test', 'test', 1);

print_r(array_combine($keys[0], $values));

//Outputs:
//Array
//(
//    [:user_pass] => test
//    [:user_id] => test
//    [:user_name] => 1
//)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.