出于速度原因,我有一个没有explisit键的罗嗦值数组。并且键自动填充为数字键0-N:
$array = array('Good old days', 'Bad old days', ....);
表单中填充了预期的键值对:
key=0, value=Good old days
或
<option value="0">Good old days</option>
这很好,因为我不想长按罗嗦的密钥。
现在问题部分是,我知道如何获取密钥,但我找不到如何显示给定密钥的值的方法。也许是因为我必须循环一个条件而且如果条件满足则抓住钥匙。
如何从给定密钥中获取值?
任何提示都会非常感激。
更新
//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);
我似乎被“价值观”所困扰。
更新2 ,以防对任何人有用或有任何好处:
$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
答案 0 :(得分:1)
echo $array[0]
将打印出“过去的好日子”。
答案 1 :(得分:0)
如果您有密钥,可以使用密钥the same as always:
$array[$key]