Извлечение ключа подмножества из массива - PullRequest
1 голос
/ 23 декабря 2011

Я работаю над страницей параметров темы и пытаюсь отправить ключ 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);

Ответы [ 3 ]

2 голосов
/ 23 декабря 2011

Я думаю, вы просто хотите:

$font = 'Arial';
$css = $fonts[$font]['css'];
1 голос
/ 23 декабря 2011

Предлагаю вам прочитать PHP документацию по массивам .

В вашей конкретной ситуации вы получите доступ к данным таким образом:

$font_name = 'Verdana';
$fonts[$font_name]['css'] //"font-family: Verdana, Verdana, Geneva, sans-serif;" 
0 голосов
/ 23 декабря 2011

Это должно работать - $fonts['Arial']['css'].Просто замените «Arial» тем шрифтом, который вы ищете.

...