php - Unable to access associative array values -
i have 2 config files. first, called configs.php contains array values:
$welcomeconfigs = [   "title" => "welcome",   "description" => "a description" ]; the second file includes configs.php 1 , use array generate other variables. second file called views.php.
$viewconfigs = view . 'configs'; $pathtoviewconfigs = view . '/configs.php';  include($pathtoviewconfigs);  var_dump($$viewconfigs); in index.php:
define("view", "welcome"); include('views.php'); i need store in $title variable, example, value of associative array, when try nothing happens. tried use var_dump check if syntax correct , used en external fiddle check if wrong, nothing wrong.
when type var_dump($$viewconfigs); output { ["title"]=> string(7) "welcome" ["description"]=> string(13) "a description" }
but when type var_dump($$viewconfigs['title']); output null.
how can fix this? doing wrong?
you have use syntax:
var_dump( ${$viewconfigs}['title'] ); that interpret $viewconfigs variable name. form $$viewconfigs['title'] interpret variable name content od $viewconfigs['title'], not exists.
i hope have been clear.
(edit:) see more variable variables on php official site
Comments
Post a Comment