I already talked about trying to use the index of the array as the variable name earlier and received one answer that interested me here .
One of the answers suggested using eval (), although not recommended, due to possible security issues.
$string = 'welcome["hello"]';
eval('$' . $string . " = 'thisworks';");
// This also works : eval("$$string = 'thisworks';");
// I could then print the array keys value like this
print( $welcome["hello"] ); // Prints 'thisworks'
However, this solution is the simplest and probably the most suitable for what I want to achieve. I am actually working on a Wordpress admin panel full of various options that the user can set. Each parameter is specified through a variable containing a multidimensional array, like this (only much more):
$options = array(
array(
'id' => 'option_id',
'type' => 'text',
'value' => 'some value here'
)
);
, , . , :
foreach ( $options as $o ) {
if ( isset( $_POST[ $o[ 'id' ] ] ) ) {
$settings[ $o[ 'id' ] ] = $_POST[ $o[ 'id' ] ];
}
}
. , 'option_id [value1]'.
. , [], , ( ).
eval . , , . , , .
, , , , eval . eval ? , ? , $ PHP?