user3886556 user3886556 - 1 month ago 4
PHP Question

convert 3 arrays into 1 array

I have one array like this

Array
(
[0] => et6CX
)
Array
(
[0] => fxYlw
)
Array
(
[0] => APA91
)


I want result like

Array
(

[0] => et6CX
[1] => fxYlw
[2] => APA91
)


How it can be done? I have tried array_values(), array_merge(), etc functions but nothings goes right.

I am building an app in Laravel5.2 and this issue comes in fetching record I think. Please have a look as soon as possible

Any help will be appreciated!

Thanks in advance!

Answer

One solution is to use array_map:

<?php

$x = [['a'],['b'],['c']];

$y = array_map(function($item) {
    return $item[0];
},$x);

var_dump($y);

Output:

array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" }
Comments