foreach($_POST as $key => $value) {
if($value)
$sorted[$parent_key][$newkey] = $value;
else
unset($_POST[$key]);
$value could be ‘0’ or ‘any string text.’ How can I validate $value so it passes if a ‘0’ is entered?
I cannot use isset($value) because the $value is set from the foreach.
I cannot use empty($value) because it treats the 0 as null.
I cannot use strlen($value) because it treats the 0 as null.
I cannot use (!$value) because it treats the 0 as null.
You can use strlen($value) because it does not treat the 0 as null.
here is the proof
Outputs: