Reputation: 1783
I'm trying to do this in Object Oriented PHP, but I have an issue when recursion is used (if the first string starts with a "(", I want to check the following char), the other cases work. Here is the code:
public static function different_first($item,$item1) {
if (substr($item, 0, 1) != substr($item1, 0, 1)) {
return TRUE;
} else if (substr($item,0,1)=="(") {
Object::different_first(substr($item, 1), $item1);
} else {
return FALSE;
}
}
Upvotes: 0
Views: 419
Reputation: 5306
Missing the return as Mark mentioned. I made a few improvements to your code. This would run a lot faster.
public static function different_first($item,$item1) {
if ($item{0} == $item1{0}){
return false;
}elseif ($item{0}=="(") {
return Object::different_first($item{1}, $item1);
} else {
return true;
}
}
Upvotes: 1
Reputation: 838096
You are missing a return:
return Object::different_first(substr($item, 1), $item1);
Upvotes: 4