一个字符串,如下所示:
<ul class="page-sidebar-menu page-header-fixed page-sidebar-menu-hover-submenu " data-keep-expanded="false" data-auto-scroll="true" data-slide-speed="200">
@foreach (var menuLevelTest in ViewBag.MenuLevelTest)
{
<li class="nav-item start">
<a href="javascript:;" class="nav-link nav-toggle">
<i class="icon-home"></i>
<span class="title">@menuLevelTest.Name</span>
<span class="arrow"></span>
</a>
@if (menuLevelTest.Menu1.Count > 0)
{
<ul class="sub-menu">
@foreach (var menuLevelTest2 in menuLevelTest.Menu1)
{
<li class="nav-item">
<a href="javascript:;" class="nav-link nav-toggle">
<i class="icon-bar-chart"></i>
<span class="title">@menuLevelTest2.Name</span>
</a>
@if (menuLevelTest.Menu2.Count > 0)
{
<ul class="sub-menu">
@foreach (var menuLevelTest3 in menuLevelTest.Menu2)
{
<li class="nav-item">
<a href="javascript:;" class="nav-link nav-toggle">
<i class="icon-bar-chart"></i>
<span class="title">@menuLevelTest3.Name</span>
</a>
</li>
}
</ul>
}
</li>
}
</ul>
}
</li>
}
</ul>
从数据库获取条件字符串
想要转换为数组所以,它可以传入以下语句:
$condition = "['or',['LIKE','name','index'],['=','type',1]]";
答案 0 :(得分:2)
你可以简单地使用eval()
(不是特定于yii):
$condition = "['or',['LIKE','name','index'],['=','type',1]]";
eval("\$condition = $condition;");
详细了解eval()
。