Fetch the value from the key PHP
I have a wordy value array without explisit keys for speed reason. And the keys are populated as numeric keys 0-N automatically:
$array = array('Good old days', 'Bad old days', ....);
The form is filled up with expected key|value pairs:
key=0, value=Good old days
or
<option value="0">Good old days</option>
which is good as I don't want to have long wordy keys.
Now the issue part is, I know how to fetch the key, but I can not find a way how to display the value out of the given key. Maybe because I have to loop for a condition and than the key is grabbed if the condition met.
How do you grab the value from the given key?
Any hint would be very much appreciated.
UPDATE:
//If keys are wordy: http://fonts.googleapis.com/css?family=Quattrocento|Droid+Sans|Yanone+Kaffeesatz
$gwf_settings = array(
'base_font',
'article_title',
'site_name',
'site_slogan',
);
$gwfs = array();
foreach($gwf_settings as $key => $gwf_font) {
//dsm('KEYS: '. $key);
// parent form to check condition if we are using gwf
if (theme_get_setting($gwf_font) == 'gwf') {
$values = $gwfs[theme_get_setting($gwf_font .'_gwf')];
dsm('KEY2: '. theme_get_setting($gwf_font .'_gwf')); //ok, we have the gwf key
dsm('VALUES: '. $values); // BLANK
$gwfs[] = str_replace(' ', '+', $values);
}
}
$google_web_fonts = implode('|', $gwfs);
I seem to get stucked with "values".
UPDATE 2, in case useful to anyone, or any betterment:
$gwf_settings = array(
'base_font',
'article_title',
'site_name',
'site_slogan',
);
$gwf_gwf = array(
'base_font_gwf',
'article_title_gwf',
'site_name_gwf',
'site_slogan_gwf',
);
foreach($gwf_settings as $key => $gwf_font) {
if ( theme_get_setting($gwf_font) == 'gwf' ) {
$gwfs = array();
foreach ($gwf_gwf as $k => $gwf_setting) {
$s = theme_get_setting($gwf_setting);
$fonts = get_gwf();
if ( $s ) {
foreach ($fonts as $f => $val) {
if ( $f == $s ) {
$gwfs开发者_开发知识库[] = str_replace(' ', '+', $val);
}
}
}
}
}
}
$google_web_fonts = implode('|', $gwfs);
// The final output will be just like with wordy key version:
//http://fonts.googleapis.com/css?family=Oswald|Yanone+Kaffeesatz|Droid+Sans
echo $array[0]
will print 'Good old days'.
If you have the key, you can use it the same as always:
$array[$key]
精彩评论