I've recently implemented a class which represents a list. Internally, the list is an array.
Most of its methods work correctly. Only two are making me trouble.
The first method is the contains method. It checks if the list contains the element given to it through a parameter.
It returns true, if the list contains the element.
Here is the method:
Code: Select all
public function contains($element){
for($i=0;$i<$this->size();$i++){
if($element == $this->list[i]){
return true;
}
}
}I use this on a site where I type in the element in an input field and then post it.
Then I call following piece of code:
Code: Select all
if($l->contains($_POST['Element'])){
echo 'Element is in the list';
}else{
echo 'Element is not in the list';
}Any idea on what is wrong?