model.php
function _test() {
return $this->db->query("SELECT 'Hello world!' AS ColumnName")->result();
}
controller.php
function test() {
$response = $this->model->_test();
var_dump(array_map(function($row) { return $row->ColumnName; }, $response));
}
I'm trying to get something like this to work on our production server, which is running PHP 5.2.9, and I realized array_map
function is not working (it outputs nothing).
My development enviroment in running PHP 5.4.4, and this code works just fine, but I can't update our production server's PHP version, and I was hoping you guys could give me ideas on how to resolve this.
Thanks in advance
You cannot pass an anonymous function/lambda into array map in version of PHP less than 5.3, and you have 5.2.
You can use create_function in 5.2, but it's ugly.