Combining a describing and one array with data



PHP Snippet 1:

$lang = array('de' => 'german', 'es' => 'spanish', 'nl' => 'dutch', 'en' => 'english');

$sites = array(
    'value1' => array('en' => 35, 'de' => 54),
    'value2' => array('nl' => 543, 'en' => 234, 'es' => 2),
    'value3' => array('es' => 39)
);

printf("%-10s", "language");
$site_names = array_keys($sites);
foreach($site_names as $site_name)
{
    printf("%-10s", $site_name);
}
printf("\n%s\n", str_repeat('-', (count($site_names) + 1) * 10));

foreach($lang as $lang_short => $lang_long)
{
    printf("%-10s", $lang_short);
    foreach($sites as $site_name => $site_values)
    {
        printf("%-10d", isset($site_values[$lang_short]) ? $site_values[$lang_short] : 0);
    }
    printf("\n");
}