app_list_strings issue when using variable

Does anyone know why the following line does not work


$lstvalue = $list['listName'];
// If I debug and output this variable it does contain the correct value
foreach ($app_list_strings[$lstvalue] as $key=>$val)
{ // the code is failing    ^ at this point and buy failing I mean it does not pass into the foreach loop
     $select_option_type .= '<option value="' . $key . '">' . $val . '</option>';
}

if I hard code $lstvalue for example


foreach ($app_list_strings['phone_type_dom'] as $key=>$val)
{
     $select_option_type .= '<option value="' . $key . '">' . $val . '</option>';
}

Everything works as expected. and all the options are listed. In PHP you should be able to use the variable and access it this way

Am I missing something here?

1 Like

is that phone_type_dom is an array or only the $app_list_strings is an array?

if Yes, You can use

foreach(app_list_strings  as $item){
echo $item['phone_type_dom'];
}