0

how do i combine these arrays and use a specific value as key/index?
here's sample array i'm playing with:

Array  
(  
    [0]=>john   
    [1]=>peter  
)  

Array  
(  
    [dept]=>engineering  
    [sub]=>trigonometry  
    [time]=>08:00  
 )  

what i want to achieved is like this:

Array  
(  
    [john]=>john  
    [dept]=>engineering  
    [sub]=>trigonometry  
    [time]=>08:00    

    [peter]=>peter
    [dept]=>engineering  
    [sub]=>trigonometry  
    [time]=>08:00   
)  

thanks in advance guys, hope u can help me with this. appreciate it.

3
  • 2
    What you want to achieve cannot be achieved because it has duplicate keys Commented Feb 7, 2013 at 12:35
  • what php code u have used to fetch this records? Commented Feb 7, 2013 at 12:36
  • What have you tried? See ask advice, please. Commented Feb 7, 2013 at 12:38

1 Answer 1

1

I think you may want to associate the value of the first array with the values of the second array.

$finalArray = array();
foreach($firstArray as $name) {
    $finalArray[$name] = $secondArray;
}
print_r($finalArray);

You will get :

Array
(
    [john] => Array
              (
                  [dept]=>engineering  
                  [sub]=>trigonometry  
                  [time]=>08:00  
              )
    [peter] => Array
              (
                  [dept]=>engineering  
                  [sub]=>trigonometry  
                  [time]=>08:00  
              )
)

Does this help you?

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

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.