Create an array with dynamic variables

2

I needed to create dynamic variables and I used this script:

for($i=1;$i<=40;$i++){
   ${"horario" . $i} = get_custom_field('horario'.$i);
}

It generates the variables $ schedule1, $ schedule2, ...

Now I need to group all these variables into an array. How do I do this?

    
asked by anonymous 04.09.2014 / 18:11

1 answer

5

I think this would be a solution.

for($i=1;$i<=40;$i++){
   $myArray[${"horario" . $i}] = get_custom_field('horario'.$i);
}

In this case the variable $ myArray would have the list of all variables and their value.

    
04.09.2014 / 18:21