0

My array is a list of countries, country codes to be exact.

$nazioni = array(
    'all' => array(
        'ad','ae','af','ag','al','am','ao','ar','at','au','az','ba','bb','bd',
        'be','bf', etc... ...'zw',
    ),

    'europa' => array(
        'ad','al','am','at','az','ba','be','bg','by','ch','cy','cz','de','dk',
        'ee','es','fi','fr','gb','ge','gr','hr','hu','ie','is','it','kz','li',
        'lt','lu','lv','mc','md','me','mk','mt','nl','no','pl','pt','ro','rs',
        'ru','se','si','sk','sm','tr','ua','va',
    ),

    'asia' => array(
        'ae','af','am','az','bd','bh','bt','bn','cn','cy','ge','id','il','in',
        'iq','ir','jo','jp','kg','kh','kp','kr','kw','kz','la','lb','lk','mm',
        'mn','mv','my','np','om','ph','pk','ps','qa','ru','sa','sg','sy','th',
        'tj','tl','tm','tr','uz','vn','ye',
    ),

etc...

This list, with continents, will also contain regions like the Mediterranean or the Middle East, which means that values will repeat in the categories. Even the basic Asia and Europe categories will contain duplicate values, and I'll use each value to create a link.

I'm very flexible on re-aranging how my array is placed, but is it even possible to take such a list and make a categorically arranged list without the overhead of the duplicate values? Or is this overhead so small that this is a non issue?

Currently I arrange it using a rudimentary foreach loop, as such:

    echo '<li>'.Lang::line('nations.europa')->get().'</li>';
    foreach($nazioni['europa'] as $n) {
        echo '<li>'.Filtra::uri(Lang::line('nations.'.$n)->get(), $uri, 1, $n).'</li>';
    }

The Filtra::uri function makes a link of it, and I look up the country by key value using the Lang::line function from the Laravel framework. Basic.

What I want in the end is a categorised list of links. The design isn't finalised but so far the returned HTML looks somewhat like this, and I'll wrap the categories in something to make it more interactive at a later stage. Maybe use DL, DT and DD tags or make an options list out of it but that's beside the point.

<li>Europe</li>
<li><a href="http://example.ex/en/+Andorra">Andorra</a></li>
and same for all Europe countries...

<li>Asia</li>
<li><a href="http://example.ex/en/+United+Arab+Emirates">United Arab Emirates</a></li>
and same for all Asian countries......

1 Answer 1

1

is it even possible to take such a list and make a categorically arranged list without the overhead of the duplicate values? Or is this overhead so small that this is a non issue?

The overhead is very small - do what will be cleaner and easier for others (or future you) to understand when reading your code

Sign up to request clarification or add additional context in comments.

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.