0
나는 약간의 프로그래밍 경험을 가지고 있으므로 기본 PHP에서 클래스, 함수 등을 사용하여 점프하는 것은 약간 힘듭니다. 내가 뭘 "테마"을 작동하는 작은 PHP 스크립트를 짓고 있어요반복 된 PHP 덩어리를 함수로 변환 하시겠습니까?
는 사용자가 양식을 선택하고 그 선택에서, 일부 특정 파일을로드합니다. 작동하는 스크립트를 만들었지 만 반복이 너무 많아 농담입니다.
// Add our theme names to variables
$theme1 = "theme1";
$theme2 = "theme2";
$theme3 = "theme3";
// Test to see what Theme the user chose.
// Theme 1
if ($themeChoice==$theme1)
{
// Load the theme
$homepage = file_get_contents('../themes/'.$theme1.'/index.html');
$mobile_js_main = file_get_contents('../themes/'.$theme1.'/js/main.js');
$mobile_js_jquery = file_get_contents('../themes/'.$theme1.'/js/jquery.js');
$mobile_css_easy = file_get_contents('../themes/'.$theme1.'/css/easy.css');
$mobile_images_bg = file_get_contents('../themes/'.$theme1.'/images/bg.png');
$mobile_images_footer = file_get_contents('../themes/'.$theme1.'/images/footer.png');
$mobile_images_nav = file_get_contents('../themes/'.$theme1.'/images/nav.png');
if ($AddPortfolioPage != '')
{
$portfolioPage = file_get_contents('../themes/'.$theme1.'/portfolio.html');
}
if ($AddContactPage != '')
{
$ContactPage = file_get_contents('../themes/'.$theme1.'/contact.html');
}
if ($AddBlankPage != '')
{
$blankPage = file_get_contents('../themes/'.$theme1.'/blank.html');
}
}
다음은 각 테마에 대해 반복됩니다.이 작업은 분명히 이상적인 방법은 아닙니다. 어떤 도움을 많이 주시면 감사하겠습니다!
간단! 감사합니다 :) – tctc91
for 루프는 완전히 쓸모가 없습니다 ... 그는 단지 in_array()를 사용하여 배열에 테마가 있는지 확인할 수 있습니다 – shesek
@shesek - 존재를 확인하는 것이 코드 샘플의 요점이 아닙니다. – nickb