0

I have this array $theme_name

Array
(
    [0] => template0
    [1] => template1
    [2] => template2
    [3] => template3
    [4] => template4
    [5] => template5
    [6] => template6
)

and this other array that has the same lenght $theme_info

Array
(
    [0] => my template n 00
    [1] => my template n 01
    [2] => my template n 02
    [3] => my template n 03
    [4] => my template n 04
    [5] => my template n 05
    [6] => my template n 06
)

Basically what I want is to have this array :

Array
(
    [template0] => my template n 00
    [template1] => my template n 01
    [template2] => my template n 02
    [template3] => my template n 03
    [template4] => my template n 04
    [template5] => my template n 05
    [template6] => my template n 06
)

Why this won't work ?

foreach ($themes_info as $key => $value) {
    include($value['directory']) ;
    $theme_info[] = $info;
    $theme_name[] = $value['name'];
}


 foreach ($theme_name as $key => $value) {
    $value = $theme_info[$key];
}

FYI $themes_info have all the themes with names and directories emplacement.

2 Answers 2

3

Use array_combine():

$result = array_combine($theme_name, $theme_info);

Demo

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

2 Comments

Thanks that's very simple!
@user3350731: Indeed. PHP has an exhaustive list of functions. You should consult it before trying to implement it manually ;)
2

You can do this far easier in PHP. Just like this:

for ($i = 0; $i < count($themes_info); $i++) {
   include($value['directory']);
   $theme_info[] = $info;
   $theme_name["someKey$i"] = $value['name'];
}

And replace someKey with your prefered key for that array. Or for any other array for that matter.

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.