1

This is my array

Array
(
[0] => Array
    (
        [0] => SC1MTTCS6J1WK
    )

[1] => Array
    (
        [0] => SC1MTTCSHJ1WK
    )
)

But when I try to implode them using

$in_text = implode(",", $myArray3);

I can't get the value instead I got this:

Array,Array

Please assist thank you.

LF00
  • 24,667
  • 25
  • 136
  • 263
Ku Syafiq
  • 63
  • 6
  • Kindly visit this link. https://stackoverflow.com/questions/16710800/implode-data-from-a-multi-dimensional-array – Noel B. Dec 05 '17 at 03:38

4 Answers4

2

Here is the simple code, try this

$in_text = implode(',',array_map('implode',$myArray3));
echo $in_text;
Muhammad Sadiq
  • 1,119
  • 12
  • 13
0

Try this code,

$in_text = '';
foreach ($myArray3 as $key=>$val){
    if(is_array($val)) {
        $in_text .= ($in_text != '' ? ',' : ''). implode(",", $val);;
    } else {
        $in_text .= ($in_text != '' ? ',' : ''). $val;
    }
}
echo $in_text;

PS: This will work upto two dimensional array.

Naga
  • 2,170
  • 3
  • 15
  • 21
0

Or, if you want to get fancy, use RecursiveIteratorIterator and RecursiveArrayIterator to flatten the array before imploding.

<?php
$array = [
    ['SC1MTTCS6J1WK'],
    ['SC1MTTCSHJ1WK']
];

$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));
$flat = [];
foreach ($it as $value) {
    $flat[] = $value;
}

echo implode(', ', $flat); //SC1MTTCS6J1WK, SC1MTTCSHJ1WK

https://3v4l.org/kDU2O

Lawrence Cherone
  • 44,769
  • 7
  • 56
  • 100
0

You call implode on an array of array, which result the Array, Array. You can call like this,

implode(",", array_column($myArray3, 0));
LF00
  • 24,667
  • 25
  • 136
  • 263