我正在处理主题选项页面,并尝试将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);
答案 0 :(得分:2)
我想你只是想:
$font = 'Arial';
$css = $fonts[$font]['css'];
答案 1 :(得分:1)
我建议你阅读PHP documentation on arrays。
在您的具体情况下,您将以下列方式访问数据:
$font_name = 'Verdana';
$fonts[$font_name]['css'] //"font-family: Verdana, Verdana, Geneva, sans-serif;"
答案 2 :(得分:0)
这应该有效 - $fonts['Arial']['css']
。只需将'Arial'替换为您要查找的任何字体。