I'm having a problem when converting a string to an object. Here is the function:
public function slikepoid($dire,$id)
{
$this->dire=$dire;
$this->id=$id;
$slike = $this->skupljanjeslika($this->dire);
$slikeid = array_filter($slike, function($el) {
return substr( $el, 0, 2) == '$this->id-'; // Here is the problem !
});
return $slikeid;
}
I got this error:
Fatal error: Using $this when not in object context on line 8
I tried:
return substr( $el, 0, 2) == ''.(string)$this->id;'-';
But no luck :(
You should be able to use a closure to accomplish this:
$slikeid = array_filter($slike, function($el) use( $id) {
return substr( $el, 0, 2) == $id;
});
Now, $id
should be inside the scope of the anonymous function, so you should be able to compare the element value against it.