PHP에서 작업 중이며 내부에서 다음 함수를 호출하면 foreach{}
루프가됩니다. 이 함수는 불필요한 코드 반복을 피하기 위해 옵션 매개 변수로 $subTheme
을 수락해야합니다 (DRY, 맞습니까?). -PHP : 배열 선언의 변수
그래서, 우선 여기 함수의 :
/*
* CSS needed to apply the selected styles to text elements.
*/
function this_site_text_css($subTheme = '') {
$GLOBALS['this_theme_mod']; // this is in global scope already
$themeVarSuffix = $subTheme['var_suffix'];
$themeClassName = $subTheme['class_name'];
$content_bg_color = $this_theme_mod['content_bg_color' . $themeVarSuffix ];
$page_bg_color = $this_theme_mod['page_bg_color' . $themeVarSuffix ];
$primary_color = $this_theme_mod['primary_theme_color' . $themeVarSuffix ];
$css = 'body' . $themeClassName . '{ /* special classes */ };'
return $css
}
일이 더있다하지만 오히려 지루한 그냥 반환하는 문자열로 CSS를 연결합니다.
은 내가 PHP 경고 Illegal string offset 'class_name'
받고 있어요 내가 PHP가 $themeClassName
에 그것을 선언 할 때 나를 $themeVarSuffix
인라인을 연결하고 싶지 않기 때문입니다 추측하고있어이
$data = '';
$data .= this_site_text_css();
$subThemeArray = array(
'theme_a' => array(
'var_suffix' => '_theme_a',
'class_name' => '.theme-a',
),
'theme_b' => array(
'var_suffix' => '_theme_b',
'class_name' => '.theme-b',
),
);
foreach($subThemeArray as $key => $theme) {
$data .= this_site_text_css($theme);
}
처럼 호출되는 것. 나는 이것을 할 수있는 방법이 있음을 확신하고 있으며, 나는 모든 것을 조사했다. 아마도 적절한 키워드를 검색하지 않았을 지 모르지만, 어떤 도움을 주시면 감사하겠습니다.
감사를 호출해야합니다! 그것뿐이었습니다. 그냥해야했습니다. 'function this_site_text_css ($ subTheme = array()) – Brian