Create an array with dynamic variables

Asked

Viewed 74 times

2

I needed to create dynamic variables and used this script:

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

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

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

1 answer

5


I think that would be a solution.

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.