以下是数组的结果
Array
(
[0] => Array
(
[0] => test
[1] => cate
[2] => category
)
)
我希望结果是
$availableTags = ["test","cate","category"];
如何在codeigniter php中执行此操作
答案 0 :(得分:3)
这不是特定于代码点火器的。该数组目前看起来像这样:[["test","cate","category"]]
,所以只需$availableTags = $originalArray[0];
要复制:
$availableTags = array_slice($originalArray[0],0);
并进行字符串化:
echo json_encode($availableTags);
答案 1 :(得分:2)
$array = $array[0];
应该够了
$array = [["test","cate","category"]];
var_dump ($array);
$array = $array[0];
var_dump ($array);
输出:
array(1) { [0]=> array(3) { [0]=> string(4) "test" [1]=> string(4) "cate" [2]=> string(8) "category" } }
array(3) { [0]=> string(4) "test" [1]=> string(4) "cate" [2]=> string(8) "category" }
答案 2 :(得分:0)
简短的方式 [混合了json_encode和str_replace并爆炸]
<?php
$data = array('foo',
'baz',
'cow',
'php',
array('bar','dog','xml'));
//Results as string
$stringRes = str_replace(array('[', '"',']'), '' , json_encode($data));
//Results as array
$arrayRes = explode(',', str_replace(array('[', '"',']'), '' , json_encode($data)));
?>
<强>输出强>
FOO,巴兹,牛,PHP,酒吧,狗,XML
数组([0] =&gt; foo [1] =&gt; baz [2] =&gt;牛[3] =&gt; php [4] =&gt; bar [5] =&gt;狗[6] ] =&gt; xml)