我被困在这个我有多个关联数组,我想转换成一个:-这是数组:-
Array
(
[0] => Array
(
[0] => Women
)
[1] => Array
(
[0] => children
[1] => smile
)
[2] => Array
(
[0] => Abstract
)
[3] => Array
(
[0] => Lion
[1] => Cheetah
)
)
我想输出类似这样的东西:
Array
(
[0] => Women
[1] => children
[2] => smile
[3] => Abstract
[4] => Lion
[5] => Cheetah
)
到目前为止,我在这里已经尝试过:
$getKeywords = DB::table('contributor_images')->select('keywords')->get();
$getKeywords = json_decode(json_encode($getKeywords),true);
foreach($getKeywords as $keyword){
$AllKeywords[] = $keyword['keywords'];
}
foreach ($AllKeywords as $key => $ExplodeKeywords) {
$searchkeywords[] = explode(',',$ExplodeKeywords);
}
echo "<pre>"; print_r($searchkeywords); die;
我正在使用php的laravel框架。提前致谢 :)
您可以为此使用Laravel帮助器函数array_flatten:
$array = [
0 => [
0 => 'Women',
],
1 => [
0 => 'children',
1 => 'smile',
],
2 => [
0 => 'Abstract',
],
3 => [
0 => 'Lion',
1 => 'Cheetah',
],
];
$result = array_flatten($array);
var_dump($result);
输出:
array (size=6)
0 => string 'Women' (length=5)
1 => string 'children' (length=8)
2 => string 'smile' (length=5)
3 => string 'Abstract' (length=8)
4 => string 'Lion' (length=4)
5 => string 'Cheetah' (length=7)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句