explode
on empty string returns array count as 1.
$consName =explode("|",$docDet['doc_cons_filename']); count($consName);
If there is some value in $docDet['doc_cons_filename']
like ab|cd|de
then count($consName)
returns 3.
But its returning 1 if $docDet['doc_cons_filename']
has empty value.
is it possible to return count as 0 if we perform count(explode("|",$docDet['doc_cons_filename']))
where $docDet['doc_cons_filename'] = ""
Can anyone help me with solution?
If the delimiter is an empty string, the split() method will return an array of elements, one element for each character of string. If you specify an empty string for string, the split() method will return an empty string and not an array of strings.
explode() is a built in function in PHP used to split a string in different strings. The explode() function splits a string based on a string delimiter, i.e. it splits the string wherever the delimiter character occurs. This functions returns an array containing the strings formed by splitting the original string.
The explode function is utilized to "Split a string into pieces of elements to form an array". The explode function in PHP enables us to break a string into smaller content with a break. This break is known as the delimiter.
The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.
The solution would be to count explicitly how many times separator is found within your string. See substr_count()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With