0

I have 2 arrays Array 1

[display_options_checkbox] => Array
        (
            [body] => body
            [nid] => nid
            [title] => 0
            [created] => 0
            [changed] => 0
        )

and Array 2:

[midsvn] => Array
(
[mid_radio_body] => Desc
    [mid_radio_nid] => Assc
    [mid_radio_title] => Assc
    [mid_radio_created] => Assc
    [mid_radio_changed] => Assc
)

How to map the keys of display_options_checkbox to the key value of of midsvn array?

For example: Can I get this kind of array structure?

Array(
[body] => array(
[mid_radio_body] => Desc
)
[nid] => array(
[mid_radio_nid] => Assc
)

and so on..

or

Array(
[body] => Desc,
[nid] => Assc,
[title] => Assc,
[created] => Assc,
[changed] => Assc
)
2
  • You'd have to have something that connects them, a ID would be most common for a loop or similar, otherwise you could do something simple as $display_options_checkbox['body'] = $midsvn['mid_radio_body']; Commented Aug 12, 2015 at 9:35
  • The order will be same all the time? Commented Aug 12, 2015 at 9:35

2 Answers 2

1

For the first result:

$result = array();
foreach (array_keys($array1['display_options_checkbox']) as $key) {
    $result[$key] = array('mid_radio_' . $key => $array2['midsvn']['mid_radio_' . $key]);
}

For the second result:

$result = array();
foreach (array_keys($array1['display_options_checkbox']) as $key) {
    $result[$key] = $array2['midsvn']['mid_radio_' . $key];
}
Sign up to request clarification or add additional context in comments.

Comments

0
foreach($array1 as $key1 => $value1){
    if(array_key_exists($key1,$array2)){
        /* do your mapping stuff here */
    }
}

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.