CakePHP3: Fetch a particular column from all rows

Say we have the following data in a table called countries:

id country capitol
1 USA Washington DC
2 Japan Tokyo
3 United Kingdom London


And you want to fetch data like this:

['Washington DC', 'Tokyo', 'London']


Then do this:

$capitols = $this->countries
->find()
->extract('capitol')
->toArray();

#cakephp3

People Who Wowed This Post

×
  • If you are a bloguru member, please login.
    Login
  • If you are not a bloguru member, you may request a free account here:
    Request Account