从数组中提取子集键
我正在开发主题选项页面,并尝试将 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);
I am working on a theme options page and trying to send the css
key to my php css
file. I can select the array key
from the parent array but i do not know how to grab the css key
from the subset. Can anyone assist me on this? I'm quite green to php
and am doing my best to learn.
Thanks!
$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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想你只是想要:
I think you just want:
我建议您阅读有关数组的 PHP 文档。
在您的具体情况下,您可以通过以下方式访问数据:
I suggest you read the PHP documentation on arrays.
In your specific situation, you would access the data in a manner such as this:
这应该有效 -
$fonts['Arial']['css']
。只需将“Arial”替换为您要查找的任何字体即可。This should work -
$fonts['Arial']['css']
. Just replace 'Arial' with whatever font you're looking for.