Arthur Tarasov Arthur Tarasov - 6 months ago 7
PHP Question

How to merge two arrays within a variable?

I have an array of two arrays that I am trying to merge into one array. My arrays are in a variable

$arr
,
var_dump
of which looks like this:

array (size=2)
0 =>
array (size=1)
0 => string 'onetag' (length=6)
1 =>
array (size=1)
0 => string 'anothertag' (length=10)


Applying
$marr = array_merge($arr)
doesn't appear to do anything. I am trying to get the merged array to look like this
['onetag', 'anothertag']
, or upon
var_dump
like this:

array (size=2)
0 => string 'onetag' (length=6)
1 => string 'anothertag' (length=10)

Answer

Use below code

$arr = array_column($arr,0);
var_dump($arr);

OUTPUT :

array (size=2)
  0 => string 'onetag' (length=6)
  1 => string 'anothertag' (length=10)
Comments