-2

I need to explode stdentid array in comma separated value.currently the studentid array is in multidimensional array i need all the value should be in comma separated

The result should be for studentid array is

[studentid] => 36399,96500,96503,96509,96512 and so on..

Array
(
    [started] => 1
    [studentid] => Array
        (
            [1] => Array
                (
                    [0] => 36399
                )

            [2] => Array
                (
                    [0] => 96500
                    [1] => 96503
                    [2] => 96506
                    [3] => 96509
                    [4] => 96512
                    [5] => 96515
                )

            [3] => Array
                (
                    [0] => 96501
                    [1] => 96504
                    [2] => 96507
                    [3] => 96510
                    [4] => 96513
                )

            [4] => Array
                (
                    [0] => 96502
                    [1] => 96505
                    [2] => 96508
                    [3] => 96511
                    [4] => 96514
                )

        )

    [name] => Test
    [name_or_email] => 
    [submitbtn] => 1
)
Sandeep
  • 113
  • 1
  • 1
  • 7

1 Answers1

-1

assuming your variable is $studentsResult (which contains the whole array you have posted)

in that case:

foreach($studentsResult['studentid'] as $studentId => $studentValues){
    $tempStudents[$studentId] = join(',',$studentValues);
}

and then $tempStudents is what you're probably looking for\

If, however all those IDs needs to be under that ONE student, then you haven't said where is the ID, but you can follow the answer on flattening the array in one of the comments or do:

$tempStudents = [];
foreach($studentsResult['studentid'] as $someId => $studentValues){
    $tempStudents = array_merge($tempStudents,$studentValues);
}
echo join(',',$tempStudents);
Jan Myszkier
  • 2,714
  • 1
  • 16
  • 23