Reputation: 4519
When I call the search_array
function, I get this error:
Call to undefined function search_array()
Even if I make all the function public, it doesn't work. How is this possible?
function search_array($needle, $haystack) {
if(in_array($needle, $haystack)) {
return true;
}
foreach($haystack as $element) {
if(is_array($element) && search_array($needle, $element))
return true;
}
return false;
}
public function do(){
$excist = $this->search_array($test[2], $allValuta);
}
Upvotes: 1
Views: 91
Reputation: 4097
Modify your codes to be like this:
function search_array($needle, $haystack) {
if(in_array($needle, $haystack)) {
return true;
}
foreach($haystack as $element) {
if(is_array($element) && $this->search_array($needle, $element))
return true;
}
return false;
}
public function do(){
$excist = $this->search_array($test[2], $allValuta);
}
Tell me if it works.
Upvotes: 1
Reputation: 11987
In codeigniter, to call a function you should use $this->
. So add $this->
to search_array()
Like this,
if(is_array($element) && search_array($needle, $element))
to
f(is_array($element) && $this->search_array($needle, $element))
^ ^
Upvotes: 0
Reputation: 136
Are you in a class ? If not, you are defining a function search_array(). So you should not call it with **$this->**search_array(...), this scheme is the use for a method of a class.
In short : remove the $this->
Upvotes: 0