0

how to add data in array with a loop

example array required

$get_id = array(
array('id' => '1', 'updated' => '2012-08-11T04:08:53+01:00'));

data required to add in the array

 ID
-----
1
2
3
4

please note that key is important in this case

output should be like

$get_id = array(
array('id' => '1', 'updated' => '2012-08-11T04:08:53+01:00'),
array('id' => '2', 'updated' => '2012-08-11T04:08:53+01:00'),
array('id' => '3', 'updated' => '2012-08-11T04:08:53+01:00'),
array('id' => '4', 'updated' => '2012-08-11T04:08:53+01:00')
);

thanks for your help

0

2 Answers 2

3
foreach (array('1', '2', '3', '4') as $id) {
  $get_id[] = array('id' => $id, 'updated' => '2012-08-11T04:08:53+01:00');
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

$get_id = array(
  array('id' => '1', 'updated' => '2012-08-11T04:08:53+01:00')
);

$ids = Array('2', '3', '4');

foreach ($ids as $id) {
  $get_id[] = array('id' => $id, 'updated' => '...');
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.