拥有以下数组:
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
,class
或任何其他子数组,并将其值转换为包含该值的变量,以便我可以随时访问它我想通过像echo $title
第一部分很简单,但我想知道是否有任何自动将[data-title] => Crear grupo
转换为data-title="Crear grupo"
foreach($buttons as $button => $attribute) {
$title = $attribute['data-title'];
$classes = $attribute['class'];
echo "<li data-title='$title' class='$classes'>"
}
答案 0 :(得分:1)
试试这个:
foreach ($buttons as $button => $attribute) {
$str = "<li ";
foreach ($attribute as $attr => $val) {
$str .= $attr . '="' . $val . '" ';
}
$str .= ">";
}