Easily convert data object to array Help


#1

How do I easily convert this into an array? Can I do toArray?

$employees = TableRegistry::get(‘employees’)->find(‘all’, array(‘fields’=> array(‘EMPLOYEEID’,‘FIRSTNAME’, ‘LASTNAME’)))->toList();


#2

Is this CakePHP 2 or CakePHP 3?


#3

the version of cakephp I am using is version 3.6


#4

try using toArray():

$employees = TableRegistry::get('employees')->find('all', array('fields'=> array('EMPLOYEEID','FIRSTNAME', 'LASTNAME')))->toArray();

#5

You are using the old syntax. Better to change it to

$employees = TableRegistry::get(‘employees’)->find(‘all’)->select(array(‘EMPLOYEEID’,‘FIRSTNAME’, ‘LASTNAME’))->toArray();


#6

Awesome Thanks for your willingness to help me out !