I was recently tasked with a situation where I needed to populate about 10 different "Settings" for every user in the current database.

This example is specifically for CakePHP, however, it could easily be used elsewhere.  My goal was the following, I had an array that was key value paired as follows:

array(
 [0] => array(
  'User' => array(
   'id' => 1)
  ),
 [1] => array(
  'User' => array(
   'id' => 2)
  ),
 [2] => array(
  'User' => array(
   'id' => 3)
  ),
 [3] => array(
  'User' => array(
   'id' => 4)
  ),
)

The result I needed was as follows:

array(
 [0] => array(
  'UserSetting' => array(
   'user_id' => 1)
  ),
 [1] => array(
  'UserSetting' => array(
   'user_id' => 2)
  ),
 [2] => array(
  'UserSetting' => array(
   'user_id' => 3)
  ),
 [3] => array(
  'UserSetting' => array(
   'user_id' => 4)
  ),
)

With a few simple lines of code, I was able to quickly and easily achieve this, let me show you how.