从数组中提取子集键

发布于 2024-12-22 16:42:19 字数 2507 浏览 0 评论 0原文

我正在开发主题选项页面,并尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

内心旳酸楚 2024-12-29 16:42:19

我想你只是想要:

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

I think you just want:

$font = 'Arial';
$css = $fonts[$font]['css'];
愛放△進行李 2024-12-29 16:42:19

我建议您阅读有关数组的 PHP 文档

在您的具体情况下,您可以通过以下方式访问数据:

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

I suggest you read the PHP documentation on arrays.

In your specific situation, you would access the data in a manner such as this:

$font_name = 'Verdana';
$fonts[$font_name]['css'] //"font-family: Verdana, Verdana, Geneva, sans-serif;" 
記柔刀 2024-12-29 16:42:19

这应该有效 - $fonts['Arial']['css']。只需将“Arial”替换为您要查找的任何字体即可。

This should work - $fonts['Arial']['css']. Just replace 'Arial' with whatever font you're looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文