--Edited--
I've made a admin form which adds some custom functions to my theme. Loading the settings page I first get the current settings from the database. For this I use get_option()
.
The setting field is called product_settings
To get all values from this setting you can call it with: $option = get_option('product_settings');
The result of this is equivalent to this:
$option = [
'product_01' => [
'style' => [
'color' => [
'primary' => '#ffffff'
]
]
]
];
Now, to get the value of index 'primary' I would call it like this:
From DB:
$optionColorPrimary = get_option('product_settings')['product_01']['style']['color']['primary'];
From array:
$optionColorPrimary = $option['product_01']['style']['color']['primary'];
Now, this work all fine and that. But now comes the tricky part. The index location is passed in a string value like this:
$get_option_srt = 'product_settings[product_01][style][color][primary]';
First part is the db field. And the part after it, separated by square brackets are the nested indexes.
My Question How do I get to the nested value of this array based on the indexes from the string?
This is my attempt so far:
$get_option_srt = 'product_settings[product_01][style][color][primary]';
// split in two, to separate the field name from the indexes.
$get_option_srt = preg_split('/(\[.*\])/', $get_option_srt, 2, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
// yes, this does not work...
// The part after get_option() is wrong. Here are the nested index locations needed
$option = get_option( $get_option_srt[0] )[ $get_option_srt[1] ];
Any help is welcome.