-1
Array ( [0] => 1,2,1,23,5,2 [1] => 1,1,1,2,3,2 [2] => 2,3,4,2 )

So I have this array. I want the all data in a single array like this.How to achieve this.

Array ( [0] => 1,2,1,23,5,2,1,1,1,2,3,2,2,3,4,2)
1
  • can you add correct tags regarding the language in question? Commented Jan 27, 2022 at 6:53

3 Answers 3

1

Merge array in Codeigniter and PHP

$multiArr = Array ( 0 =>  Array (1,2,1,23,5,2),
                    1 =>  Array (1,1,1,2,3,2),
                    2 =>  Array (2,3,4,2)
                  );
//-method merge 1-//
foreach($multiArr as $val)
{
   foreach($val as $val2)
   {
      $result[]=$val2;
   }
}
//-method merge 2-//
//$result = array_merge($multiArr[0], $multiArr[1], $multiArr[2]);

foreach($result as $val)
{
    echo $val.", ";
}

result: 1, 2, 1, 23, 5, 2, 1, 1, 1, 2, 3, 2, 2, 3, 4, 2,

Sign up to request clarification or add additional context in comments.

Comments

0

Array ( [0] => 1,2,1,23,5,2 [1] => 1,1,1,2,3,2 [2] => 2,3,4,2 )

merged = array merge((spread-operator)array);

Comments

0

It seems to me that you just want to implode the comma-delimited 0 column values with the same delimiter.

Code: (Demo)

$array = [
    ['1,2,1,23,5,2'],
    ['1,1,1,2,3,2'],
    ['2,3,4,2'],
];

$result[0] = implode(',', array_column($array, 0));
var_export($result);

Output:

array (
  0 => '1,2,1,23,5,2,1,1,1,2,3,2,2,3,4,2',
)

If you'd rather simplify the result structure to a basic string, remove the [0] when making the $result assignment.

If you'd rather have separate values, just explode(',', $result[0])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.