Basically I am trying to create the following array.
$foo = array(
1 => array(
'id' => '1',
'value' => '1',
),
2 => array(
'id' => '2',
'value' => '2',
)
);
I am currently doing this like so
for($i = $rangeMin; $i <= $rangeMax; $i++) {
array_push($foo, array('id'=> $i, 'value' => $i));
}
Although this works, is there any way I can improve upon this code? or is there any pre-built functionality in PHP to already do this?
'id'part of the array is usually useless because you can just get the key withforeach($array as $key => $value) { $id = $key + $rangeMin; }or something. If you want better advice give a specific scenario.$foo = range($rangeMin, $rangeMax)would give you the same values in much less space.