我在php中有数组,例如:
if ($_GET['id1'] == "machine-category") {
$table['cols'] = array(
array('label' => 'category', 'type' => 'string'),
array('label' => 'count', 'type' => 'string')
);
}
我想传递类别中的各种值,尝试过:
if ($_GET['id1'] == "machine-category") {
$table['cols'] = array(
array("'".
"label".
"'".
" => . ".
"'".explode($GET['id1'], "-")[1].
"', '".
"type'".
" => '".
"string".
"'"),
array('label' => 'count', 'type' => 'string')
);
}
但这是行不通的。
谁能提供相同的解决方案?
我不太确定您要完成什么。也许您是说,如果您$_GET['id1']
是machine-category
,那么您想要的一行看起来像这样:
array('label' => 'category', 'type' => 'string'),
并且如果您有一个$_GET['id1']
,machine-foobar
那么您需要这样的一行:
array('label' => 'foobar', 'type' => 'string'),
那是你要的吗?在这种情况下,请尝试以下操作:
if ($_GET['id1'] == "machine-category!") {
$category_parts = explode('-', $_GET['id1']);
$category = $category_parts[1];
$table['cols'] = array(
array('label' => $category, 'type' => 'string'),
array('label' => 'count', 'type' => 'string')
);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句