Search code examples
phpcodeigniterarray-map

not able to use array map function in php


array_map() expects parameter 1 to be a valid callback, class 'Search' does not have a method 'wishList'

 $shops = array_map(array($this, 'wishList'), $shops);

 function wishList($shops) {
        print_r(shops);
        $this->check_authentication(); 
        $user = $this->getUser();
        $shops->isWishList = $this->Wishlist_model->_isShopInMyWishList($shops->id, $user->id,6) ? true : false;
        return $shops;
    }

Solution

  • For what I see that's the issue, you just declared your wishList function not in the Search class, if you wanna do this your should write this:

    $shops = array_map('wishList', $shops);
    

    Or move you wishList function to your Search class