-1

下面是数组的结果

    Array
(
    [0] => Array
        (
            [0] => test
            [1] => cate
            [2] => category
        )

)

我希望结果是

 $availableTags = ["test","cate","category"];

如何在 codeigniter php 中执行此操作

4

3 回答 3

3

这与代码点火器无关。数组当前看起来像这样:[["test","cate","category"]],所以就这样做$availableTags = $originalArray[0];

复印:

$availableTags = array_slice($originalArray[0],0);

并进行字符串化:

echo json_encode($availableTags);
于 2013-08-27T06:32:48.327 回答
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" }
于 2013-08-27T06:32:52.123 回答
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,baz,cow,php,bar,dog,xml
数组 ( [0] => foo [1] => baz [2] => 牛 [3] => php [4] => bar [5] =>狗 [6] => xml )

于 2013-08-27T07:32:58.847 回答