user1029834
user1029834

Reputation: 783

Issue with array_map callback

At first I had this (work in wamp but not in my web server)

$ids = array_map(function($item) { return $item['user_id']; }, $data['student_teacher']);`

So I try to convert the code to that but nothing work ( i got Array,Array,Array,Array,Array,Array from outpout )

$ids = array_map($this->myarraymap(null), $data['student_teacher']);

function myarraymap($item) {
        return $item['user_id']; 

    }

Upvotes: 2

Views: 1723

Answers (1)

John Cartwright
John Cartwright

Reputation: 5084

You need to pass it a callback, and not actually pass it the execution of the function, i.e.,

$ids = array_map(array($this, 'myarraymap'), $data['student_teacher']);

function myarraymap($item) {
   return $item['user_id']; 
}

Upvotes: 7

Related Questions