<?php $strings = [ "1,2,3,4", "1,2,3", "1,2" ]; $minElements = 3; $defElements = array_fill(0, $minElements, null); foreach ($strings as $string) { [$a, $b, $c] = array_replace($defElements, explode(',', $string, $minElements)); var_export($a); echo ' _ '; var_export($b); echo ' _ '; var_export($c); echo "\n-----------------\n"; }
You have javascript disabled. You will not be able to edit any code.