0

具有以下数组:

Array
(
    [new] => Array
        (
            [data-title] => Crear grupo
            [class] => test1, test2, test3
            [style] => float:left; border:1px solid red;
        )

    [trash] => Array
        (
            [class] => delete
        )

    [0] => edit
)

我想要实现的是提取data-title's、class's 或任何其他子数组,并将其值转换为包含该值的变量,这样我就可以随时通过像这样回显它来访问它echo $title

第一部分很简单,但我想知道是否有任何方法可以自动翻译[data-title] => Crear grupodata-title="Crear grupo"

foreach($buttons as $button => $attribute) {

         $title = $attribute['data-title'];
         $classes = $attribute['class'];

         echo "<li data-title='$title' class='$classes'>"

}
4

1 回答 1

1

尝试这个:

foreach ($buttons as $button => $attribute) {
    $str = "<li ";

    foreach ($attribute as $attr => $val) {
        $str .= $attr . '="' . $val . '" ';
    }
    $str .= ">";
}
于 2012-08-09T15:56:07.973 回答