2011-12-23 3 views
1

테마 옵션 페이지에서 css 키를 내 php css 파일로 보내려고합니다. 부모 배열에서 array key을 선택할 수 있지만 서브 세트에서 css key을 잡는 방법을 모르겠습니다. 아무도 이것에 나를 도와 줄 수 있습니까? 나는 매우 녹색이어서 php이며 배우기 위해 최선을 다하고 있습니다.배열에서 서브 세트 키 추출

감사합니다.

$fonts = array( 
'Arial' => array( 
    'name' => 'Arial', 
    'font' => '', 
    'css' => "font-family: Arial, sans-serif;" 
), 
'ubuntu' => array( 
    'name' => 'Ubuntu', 
    'font' => '@import url(http://fonts.googleapis.com/css?family=Ubuntu);', 
    'css' => "font-family: 'Ubuntu', sans-serif;" 
), 
'lobster' => array( 
    'name' => 'Lobster', 
    'font' => '@import url(http://fonts.googleapis.com/css?family=Lobster);', 
    'css' => "font-family: 'Lobster', cursive;" 
), 
'Lato' => array(
    'name' => 'Lobster', 
    'font' => '@import url(http://fonts.googleapis.com/css?family=Lato);', 
    'css' => "font-family: 'Lato', sans-serif;" 
), 
'Droid Sans' => array(
    'name' => 'Droid Sans', 
    'font' => '@import url(http://fonts.googleapis.com/css?family=Droid+Sans);', 
    'css' => "font-family: 'Droid Sans', sans-serif;" 
), 
'Tachoma' => array( 
    'name' => 'Tachoma', 
    'font' => '', 
    'css' => "font-family: Tachoma, Geneva, sans-serif;" 
), 
'Verdana' => array( 
    'name' => 'Verdana', 
    'font' => '', 
    'css' => "font-family: Verdana, Verdana, Geneva, sans-serif;" 
), 
'Times New Roman' => Array(
    'name' => 'Times New Roman', 
    'font' => '', 
    'css' => "font-family: Times New Roman, Times New Roman, serif;" 
), 
'Georgia' => array( 
    'name' => 'Georgia', 
    'font' => '', 
    'css' => "font-family: Georgia, serif;" 
), 
'Custom Font' => array(
    'name' => $custom_family, 
    'font' => $custom_font, 
    'css' => "font-family:" . $custom_family . "sans-serif;", 
    ) 
); 
$custom_font = get_option('ideate_custom_font');  
//Extract the values from the URL String that are separated by '=' 
$name_extract = explode('=', $custom_font); 

//Find these characters in the URL string 
$find = array("+", ");"); 
//Add Space or Null the value 
$replace = array(" ",""); 
//Take the Family Value from the String and Remove any Special Characters from 'Find' array 
$custom_family_string = str_replace($find,$replace,$name_extract[1]); 
//Take Value from String Replacement and Add Quotes Around it 
$custom_family = "\"" .$custom_family_string. "\""; 
$font_array = array_keys($fonts); 

답변

2

을 나는 방금 싶은 생각 :

$font = 'Arial'; 
$css = $fonts[$font]['css']; 
+0

이것은 PHP 파일에서 로컬로 작동합니다. 어쨌든이 값을 다른 파일로 전달할 수 있습니까? – mnelson7982

+0

배열을 별도의 파일에 배치하고 두 파일의 헤더에 포함 시켰습니다. 파일에서'$ css' 변수를 호출 할 수 없습니다. 출력을 null로 지정합니다. – mnelson7982

+0

신경 쓰지 마라 ... 나는 나쁜 길을 가졌다! – mnelson7982

1

나는 PHP documentation on arrays을 읽는 것이 좋습니다. 특정 상황에서

, 당신이 이와 같은 방식으로 데이터에 액세스 할 :

$font_name = 'Verdana'; 
$fonts[$font_name]['css'] //"font-family: Verdana, Verdana, Geneva, sans-serif;" 
0

이 작동합니다 - $fonts['Arial']['css']. 'Arial'을 원하는 폰트로 바꿉니다.