3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 0 => 'Title', 1 => 'image_url', 3 => 'SKU CODE', 4 => 'TITLE SIZE', 5 => 'DESCRIPTION', 6 => 'BASE SKU', ], [ 0 => 'A witch and her cat live here', 1 => 'https://beautifulhomegifts.com/a-witch-and-her-cat-live-here/', 3 => [ 0 => 'BHG-MS-AWAHCLH030720', 1 => 'BHG-MS-AWAHCLH030720-A5', 2 => 'BHG-MS-AWAHCLH030720-A4', 3 => 'BHG-MS-AWAHCLH030720-A3', ], 4 => [ 0 => 'A witch and her cat live here', 1 => 'A witch and her cat live here - 150mm x 200mm', 2 => 'A witch and her cat live here - 201mm x 305mm', 3 => 'A witch and her cat live here - 305mm x 400mm', ], 5 => [ 0 => 'A witch and her cat live here', 1 => 'A witch and her cat live here', 2 => 'A witch and her cat live here', 3 => 'A witch and her cat live here', ], 6 => [ 1 => 'BHG-MS-AWAHCLH030720', 2 => 'BHG-MS-AWAHCLH030720', 3 => 'BHG-MS-AWAHCLH030720', ], ], 2 => [ 0 => '', 1 => '', ], 3 => [ 0 => '', 1 => '', ], 4 => [ 0 => '', 1 => '', ], 5 => [ 0 => 'Autism House Rules', 1 => 'https://beautifulhomegifts.com/autism-house-rules/', 3 => [ 0 => 'BHG-MS-AHR030720', 1 => 'BHG-MS-AHR030720-A5', 2 => 'BHG-MS-AHR030720-A4', 3 => 'BHG-MS-AHR030720-A3', ], 4 => [ 0 => 'Autism House Rules', 1 => 'Autism House Rules - 150mm x 200mm', 2 => 'Autism House Rules - 201mm x 305mm', 3 => 'Autism House Rules - 305mm x 400mm', ], 5 => [ 0 => 'Autism House Rules', 1 => 'Autism House Rules', 2 => 'Autism House Rules', 3 => 'Autism House Rules', ], 6 => [ 1 => 'BHG-MS-AHR030720', 2 => 'BHG-MS-AHR030720', 3 => 'BHG-MS-AHR030720', ], ] ]; $headers = array_shift($array); // $fhandle = fopen("new.csv", "a"); // fputcsv($fhandle, $headers); $demo[] = $headers; foreach ($array as $row) { if (empty($row[0])) { continue; } $group = array_splice($row, 0, 2); foreach ($row[0] as $column => $notUsed) { /* fputcsv($fhandle, array_merge( !$column ? $group : ['', ''], array_column($row, $column) )); */ $demo[] = array_merge( !$column ? $group : ['', ''], array_column($row, $column) ); } } // fclose($fhandle); var_export($demo);
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.24, 8.3.0 - 8.3.12
array ( 0 => array ( 0 => 'Title', 1 => 'image_url', 3 => 'SKU CODE', 4 => 'TITLE SIZE', 5 => 'DESCRIPTION', 6 => 'BASE SKU', ), 1 => array ( 0 => 'A witch and her cat live here', 1 => 'https://beautifulhomegifts.com/a-witch-and-her-cat-live-here/', 2 => 'BHG-MS-AWAHCLH030720', 3 => 'A witch and her cat live here', 4 => 'A witch and her cat live here', ), 2 => array ( 0 => '', 1 => '', 2 => 'BHG-MS-AWAHCLH030720-A5', 3 => 'A witch and her cat live here - 150mm x 200mm', 4 => 'A witch and her cat live here', 5 => 'BHG-MS-AWAHCLH030720', ), 3 => array ( 0 => '', 1 => '', 2 => 'BHG-MS-AWAHCLH030720-A4', 3 => 'A witch and her cat live here - 201mm x 305mm', 4 => 'A witch and her cat live here', 5 => 'BHG-MS-AWAHCLH030720', ), 4 => array ( 0 => '', 1 => '', 2 => 'BHG-MS-AWAHCLH030720-A3', 3 => 'A witch and her cat live here - 305mm x 400mm', 4 => 'A witch and her cat live here', 5 => 'BHG-MS-AWAHCLH030720', ), 5 => array ( 0 => 'Autism House Rules', 1 => 'https://beautifulhomegifts.com/autism-house-rules/', 2 => 'BHG-MS-AHR030720', 3 => 'Autism House Rules', 4 => 'Autism House Rules', ), 6 => array ( 0 => '', 1 => '', 2 => 'BHG-MS-AHR030720-A5', 3 => 'Autism House Rules - 150mm x 200mm', 4 => 'Autism House Rules', 5 => 'BHG-MS-AHR030720', ), 7 => array ( 0 => '', 1 => '', 2 => 'BHG-MS-AHR030720-A4', 3 => 'Autism House Rules - 201mm x 305mm', 4 => 'Autism House Rules', 5 => 'BHG-MS-AHR030720', ), 8 => array ( 0 => '', 1 => '', 2 => 'BHG-MS-AHR030720-A3', 3 => 'Autism House Rules - 305mm x 400mm', 4 => 'Autism House Rules', 5 => 'BHG-MS-AHR030720', ), )
Output for 5.4.0 - 5.4.45
Fatal error: Call to undefined function array_column() in /in/jpu81 on line 100
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/jpu81 on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/jpu81 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/jpu81 on line 3
Process exited with code 255.

preferences:
83.08 ms | 412 KiB | 5 Q