PHP: How can I access an associative array with a string using the shortest possible code?
PHP: How can I access an associative array with a string using the shortest possible code?. Do You sir & mam has this kind of query?, If yes then plz found the best tips right after below:
You don’t really want a three-dimensional array like $array[‘app’][‘database’]
<?php // Create your test input. $input = 'app/database/host'; // Split it into named variables. You could have stopped at this point. // And you would have had three simple variables: $app, $database, // and $host. list($app, $database, $host) = explode('/', $input); // Instead, you want to assign $data['app'] to $app, // $data['database'] to $database, and $data['host'] to $host $data = compact('app', 'database', 'host'); // This dumps output for purpose of illustration. var_dump($data); ?>
The result of the var_dump() is this:
array(3) 'app' => string(3) "app" 'database' => string(8) "database" 'host' => string(4) "host"
We at this web hope that those answers above could answer your problem. Thanks