tags:

views:

70

answers:

1

Basically, this is what I currently use in an included file:

    $sites[0]['url'] = "http://example0.com";
    $sites[1]['url'] = "http://example1.com";
    $sites[2]['url'] = "http://example2.com";
    $sites[3]['url'] = "http://example3.com";
    $sites[4]['url'] = "http://example4.com";
    $sites[5]['url'] = "http://example5.com";

And so I output it like so:

foreach($sites as $s)

But I want to make it easier to manage via a MySQL database. So my question is, how can I make it automatically add additional "$sites[x]['url'] = "http://examplex.com";" and output it appropriately from my MySQL table?

+1  A: 

You can use array_map() for this:

$newSites = array_map('pick_attribute', $sites, 'url');

function pick_attributes($val, $prop) {
  return $val[$prop];
}

or a simple loop:

$newSites = array();
foreach ($sites as $v) {
  $newSites[] = $v['url'];
}
cletus