mnelson7982
mnelson7982

Reputation: 427

Extracting a Subset Key from an Array

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);

Upvotes: 1

Views: 193

Answers (3)

barfoon
barfoon

Reputation: 28167

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

Upvotes: 0

sunetos
sunetos

Reputation: 3508

I think you just want:

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

Upvotes: 2

user142162
user142162

Reputation:

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;" 

Upvotes: 1

Related Questions