3v4l.org

run code in 300+ PHP versions simultaneously
<?php $rows = [['size' => 'XL,L,XXL'], ['size' => 'XL'], ['size' => 'M,L,XL'], ['size' => 'L,XL,M']]; // while ($srow = $result->fetch_assoc()) { foreach ($rows as $srow) { $sizes[] = $srow['size']; // do other stuff with fetched data // ... } $sizes = array_unique(array_map('trim', explode(',', implode(',', $sizes)))); sort($sizes); $string = implode(',', $sizes); echo $string;
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.26, 7.4.0 - 7.4.13, 8.0.0 - 8.0.2
L,M,XL,XXL