0

i would like to ask, how to make variables from the array, where some variables are variables and some arrays.

for ex: i have an array for global:

$globals = array("routes","_ARGS","DB_SERVER","DB_USER","DB_PASS","DB_NAME","conn","mysql_tables","validity_of_fields_array");

and one of the variable is array "validity_of_fields_array".

so i made a code that if some variable ends with word array, the script sets the variable an array instead just a variable

function framework_routes($rout_arg){

    global $globals;

    foreach($globals as $value) {   

        if(substr($value, count($value)-6) == strtolower("array")){         
            global $$value = array;             
        } else {    
            global $$value; 
        }
    }

this part (global $$value;) sets the variable ok, but this part (global $$value = array;) throws me an error!

if i set global $$value[]; instead of global $$value = array;

it throws me an error too.

May be someone knows how to for-each variables from an array, when some of variables are arrays?

Thank you and have a nice day !

Justin

MrJustin
  • 65
  • 5
  • Do not abuse of `global` keyword. `global` in a function means your function will be allowed to access a variable that is set outside the function scope, so basically you try to access a constant variable for example. In your loop `foreach($globals as $value)`, do not necessary put a `global ` before `$$value` as it is already setted in your function. Also, why the doubles `$` ? – Anwar Jul 21 '16 at 13:08
  • this worked. $$value. Thanks man!!! – MrJustin Aug 26 '16 at 11:32

0 Answers0