Php 将数组拆分为单独的字符串

Php 将数组拆分为单独的字符串,php,Php,我有一个数组,请看这里: foreach ($fonts as $font) { $html .= '<option value="'. $font['name'] .''. $font['font'] .''. $font['css'] .'"' . selected( $layout_options['h1-font'], ''. $font['name'] .''. $font['font'] .''. $font['css'] .'', false) . '>

我有一个数组,请看这里:

foreach ($fonts as $font) {

        $html .= '<option value="'. $font['name'] .''. $font['font'] .''. $font['css'] .'"' . selected( $layout_options['h1-font'], ''. $font['name'] .''. $font['font'] .''. $font['css'] .'', false) . '>' . __( ''. $font['name'] .'' ) . '</option>';

            $html.= $font['font'];
        $html .= '</option>';
    }
我得到了结果

string(85) "Lobster@import url(http://fonts.googleapis.com/css?family=Lobster);'Lobster', cursive"
该数组由以下变量组成

'. $font['name'] .''. $font['font'] .''. $font['css'] .'
我需要将它们分开,理想情况下我想使用

$layout_options['hi-font-css']
我该怎么做

更新:

如果我发布所有代码,希望它能解释得更多

这是我的函数,我会回到原来的代码,因为它稍微好一点

function span_font_callback() {
$layout_options = (array) get_option( 'layout_options' );
$fonts = get_fonts();
$current = 'arial';

if ( isset( $layout_options['span-font'] ) )
    $current = $layout_options['span-font'];

?>
    <select name="layout_options[span-font]">
      <option value="default">Please select an option</option>
      <?php foreach( $fonts as $key => $font ): ?>
        <option <?php if($key == $current) echo "SELECTED"; ?> value="<?php echo $key; ?>"><?php echo $font['name']; ?></option>
      <?php endforeach; ?>
    </select>
    <input type="text" name="layout_options[span_font_size]" size="6" value="<?php echo $layout_options['span_font_size']; ?>" placeholder="Size"/>
    <input type="text" name="layout_options[span_font_colour]" size="6" value="<?php echo $layout_options['span_font_colour']; ?>" placeholder="Colour"/>

<?php   
}
}

这是我的stylesheet.php

<?php $layout_options       = get_option ( 'layout_options' ); ?>

@import url(http://fonts.googleapis.com/css?family=Lobster);
.hero_text {
text-align: right;
padding-left: 5px;
display: inline;
float: right;
clear: both;
position: fixed;
right: 0;
font-family: <?php echo $layout_options['h1-font']; ?>;
font-size: <?php echo $layout_options['h1_font_size']; ?>;
color: <?php echo $layout_options['h1_font_colour']; ?>;
line-height: 20px;
}
使用字体数组,这样当我的下拉列表更改时,它将更改该行以匹配字体。我需要使用下面的东西,但特别是数组名,css和字体

<?php echo $layout_options['h1-font-']; ?>;

希望这能给您带来更多好处?

在连接
$html
字符串之前,请执行以下操作:

$layout_options['hi-font-css'] = $font['name'] . $font['font'] . $font['css'];
因此,整个代码将是:

foreach ($fonts as $font) {
        $layout_options['hi-font-css'] = $font['name'] . $font['font'] . $font['css'];
        $html .= '<option value="'. $layout_options['hi-font-css'] .'"' . selected( $layout_options['h1-font'], ''. $layout_options['hi-font-css'] .'', false) . '>' . __( ''. $font['name'] .'' ) . '</option>';

        $html.= $font['font'];
        $html .= '</option>';
}
foreach($font作为$font){
$layout_options['hi-font-css']=$font['name']。$font['font']。$font['css'];
$html.=''.'.'.$font['name'.].''.').';
$html.=$font['font'];
$html.='';
}

我不明白这个问题。您在哪里设置
$layout\u选项
?你想用什么作为分隔符来分割它?即使读了4遍,我也完全不明白你的问题是什么。。。您当前的数组是什么?您希望如何转换它?为什么要在
$font
的每个元素之间连接
'
?那没什么用。只需编写
$font['name']$字体['font']$font['css']
。您好,非常抱歉没有输入,我现在已经更新了帖子,让您了解整个代码,以帮助您理解我正在尝试做的事情,希望这会有所帮助。您不应该分配给
$layout\u options
,而不是
$font
?的确,我的错。我会解决这个问题。编辑:修复虽然这看起来比我的代码干净得多,但我需要数组显示类似[“h1字体名称”]=>string(85)“Lobster”[“h1字体”]=>string(85)”@import url();“[“h1字体css”]=>string(85)“Lobster”,草书”
<?php echo $layout_options['h1-font-']; ?>;
$layout_options['hi-font-css'] = $font['name'] . $font['font'] . $font['css'];
foreach ($fonts as $font) {
        $layout_options['hi-font-css'] = $font['name'] . $font['font'] . $font['css'];
        $html .= '<option value="'. $layout_options['hi-font-css'] .'"' . selected( $layout_options['h1-font'], ''. $layout_options['hi-font-css'] .'', false) . '>' . __( ''. $font['name'] .'' ) . '</option>';

        $html.= $font['font'];
        $html .= '</option>';
}