문제

I have a for loop in php that is throwing a peculiar error.

for ($counter=1; $counter < count($cities); $counter++)
    $dataset[$cities[$counter]]=substr_count($votecontents, $cities[$counter]);

Error:

Warning: substr_count() [function.substr-count]: Empty substring in [OMITTED] on line 24

Line 24 is the second line I showed. I know that the array $cities is populated because I checked it right before. I start with $counter equaling one because I don't want to use the first entry of the array.

What's going on here?

도움이 되었습니까?

해결책

It simple means that $cities[$counter] is empty string. You need to add extra check before using substr_count function.

If you have for example code:

$array = array();

$array[] = '';

array will have one element, but when you use this element in substr_count function it will raise warning

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top