Can I index an array variable inside a string with double quotes PHP?

I have an array of custom hooks that I would like to plan, built on these lines:

public function __construct(WPSM_Logger $injected_logger = null) {
    $this->cron_hooks[WPSM_CRONHOOK_SENDQUEUE] = array ("frequency" => 60);
}

Then, in the constructor for my Scheduler class, I would like to loop into $ this-> cronhooks and schedule every hook in this array. I usually prefer direct and simple variable expansion in double quotes, for example, what I am doing with the name $ name below, but I cannot figure out how to do this with an array and an index.

foreach ($this->cron_hooks as $name => $options) {
    $freq = $options["frequency"];
    echo "Hook '$name' will run every $freq seconds.";  
}

I would like to end the intermediate line $freq = $options["frequency"];and have something like this in the line echo:

foreach ($this->cron_hooks as $name => $options) {
    $freq = $options["frequency"];
    echo "Hook '$name' will run every $options['frequency]seconds.";    
}

However, I just can't get it to work. Is there something special I'm missing out on, or do I really need to drag an extra variable along with my side?

+6
2

?

foreach ($this->cron_hooks as $name => $options) {
    echo "Hook '$name' will run every ${$options['frequency']} seconds.";    
}
+8

All Articles