|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-03-24 11:18 UTC] cmb@php.net
-Status: Open
+Status: Not a bug
-Assigned To:
+Assigned To: cmb
[2021-03-24 11:18 UTC] cmb@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 15:00:01 2025 UTC |
Description: ------------ Version: 7.4.15-5+deb11u1 When you explode a string into an array, elements that contain nothing (null) are detectable as such via is_null. The only way to tell is any array element doesn't contain a value is to strlen(trim($a_array[2])) == 0, which gives you the result you want, but is a tad tedious. I'm sure in prior versions is_null($a_array[2] would return true when that array element is empty. I cannot prove or disprove this as I don't have access to an older version of PHP. Test script: --------------- <?php $a_string = "awsed|34r5|||gh||"; $a_array = explode ("|", $a_string); if (is_array($a_array)) { $a_count = count($a_array); echo "Number of Elements " . $a_count . PHP_EOL; for ($i = 0; $i < $a_count; $i++) { if (is_null($a_array[$i])) { echo "Element " . $i . " Is NULL" . PHP_EOL; } else { echo "Element " . $i . " is " . $a_array[$i] . PHP_EOL; } } } else { echo "NOT AN ARRAY" . PHP_EOL; } ?> Expected result: ---------------- Number of Elements 7 Element 0 is awsed Element 1 is 34r5 Element 2 Is NULL Element 3 Is NULL Element 4 is gh Element 5 Is NULL Element 6 Is NULL Actual result: -------------- Number of Elements 7 Element 0 is awsed Element 1 is 34r5 Element 2 is Element 3 is Element 4 is gh Element 5 is Element 6 is