Include file in array

后端 未结 2 1379
无人共我
无人共我 2021-01-15 04:37

I have this code

$__routes = array(

\"Home\"                    => \"index.php\",
\"Contact\"                 => \"contact.php\",
\"Register\"                 


        
相关标签:
2条回答
  • 2021-01-15 04:49

    If I'm understanding your intention correctly, You could include one file into the other one and merge the arrays:

    $merged_aray = array_merge($__routes, $array2);
    

    Where $array2 equals:

    "Support"                 => "support.php",
    "Success"                 => "success.php",
    "Act"                     => "activate.php"
    
    0 讨论(0)
  • 2021-01-15 05:01

    Not without changing example.php. Each file must be valid PHP code on its own, because the include only happens at runtime (i.e. when this exact line of code is reached), not at parse time (i.e. when the file is loaded)

    One way to accomplish what you need would be

    example.php

    return array(
        "Support"                 => "support.php",
        "Success"                 => "success.php",
        "Act"                     => "activate.php"
    );
    

    main file

    $__routes = array(
        "Home"                    => "index.php",
        "Contact"                 => "contact.php",
        "Register"                => "register.php"
    ) + (include 'example.php');
    
    0 讨论(0)
提交回复
热议问题