0

I'm having a simple issue that I've been beating my head against the screen trying to figure out. I have a variable $sceneArray that holds the array listed below. I also have another variable $locateRecord that holds something like ['opening']['scene2'].

Ordinarily, to get the value of scene2, I would just reference $sceneArray['opening']['scene2']. But in this case, I need to combine the two variables to retrieve that value. I have tried things like ${sceneArray.$locateRecord} but that isn't work for me either.

Would appreciate any hint!

EDIT: I have the ability to format the $locateRecord value in a different way if that can solve this. For example, I could structure it as opening>scene2 or opening,scene2 etc.

Array
(
  [opening] => Array
    (
      [scene1] => 1:00
      [scene2] => 2:00
    )

  [closing] => Array
    (
      [scene3] => 3:00
      [scene4] => 4:00
    )
)
Jason
  • 1,105
  • 3
  • 16
  • 30
  • What do you get? Do you get an error? If you get an error can you please post it :D – Nathaniel Eskenazi Jan 27 '21 at 17:48
  • There are [many](https://stackoverflow.com/questions/7003559/use-strings-to-access-potentially-large-multidimensional-arrays) questions [on this site](https://stackoverflow.com/questions/10466815/php-variable-variables-with-array-key) that deal with a [similar issue](https://stackoverflow.com/questions/27789932/get-value-from-array-using-string-php). That should get you started on the right path. – El_Vanja Jan 27 '21 at 17:50
  • @NathanielEskenazi Thank you for the reply! No error - just an empty value. – Jason Jan 27 '21 at 17:51
  • `eval` is the first thing that comes to mind. But there will be a bunch of people who don't like it. Can you afford, memory-wise, to build another data structure where `['opening---scene2']` is present? – qräbnö Jan 27 '21 at 17:52
  • @El_Vanja Thank you for the links. I've tried those approaches and, unfortunately, still not having any luck. – Jason Jan 27 '21 at 18:47

0 Answers0