0

I am using follwoing array to create an input:

$input = array(
   'data' => 'options',
   'name' => '[top_banner][item_1][visible]',
   'type' => 'text'
)

following input gets rendered from the above php array

<input type="text" name="options[top_banner][item_1][visible]" value="">

now i have another array which stores the value when the form is submitted.

$array = array (
  'options' => 
  array (
    'top_banner' => 
    array (
      'item_1' => 
      array (
        'visible' => 'true',
        'content' => 'Some Text',
        'link' => 'https://example.com',
        'link_text' => 'Click',
        'speed' => '2000',
      )
    )
  )
)

here i am creating an array from the name of $input like this:

$name = array(
    [0] => top_banner
    [1] => item_1
    [2] => visible
)

To get the value of the input i could use follwoing:

$value = $array['options']['top_banner']['item_1']['visible'];

HERE I AM STUCK - How can i build the $value from the $name array without doing this manually?

I have tried in foreach function but i am missing something..

foreach ($name as $data) {

    $build_value_structure_from_keys[] = $data ;

}

$value = $array['options'][$build_value_structure_from_keys]
Nash
  • 227
  • 1
  • 13

0 Answers0