Order a list of categories by number of entries, key not being set I have modified the code from this question but I'm running into an issue. 

{% set allCats = craft.categories.group('blogCategories').level(1).find() %}

{% set catArray = {} %}

{% for cat in allCats %}

    {% set catArray = catArray | merge({(cat.id):craft.entries.relatedTo(cat).total() }) %}

{% endfor %}

{% set catArray = catArray|sort|reverse %}

{% for catId, count in catArray %}

    {% set category = craft.categories.id(catId).first() %}

    &lt;li&gt;
        &lt;a href="{{ category.url }}"&gt;{{ category.title }} &lt;span&gt;{{count}}&lt;/span&gt;&lt;/a&gt;
    &lt;/li&gt;

{% endfor %}


Ive ran a dump on the catArray array and the category id isnt being set as the key, regardless of if I try put brackets around it to protect it, I only get the value in the array.
If you encounter problems with assigning variables as the keys, what about putting all your values into objects?

{% set catObjects = [] %}

{% for cat in allCats %}

    {% set catObject = [
        { catId: cat.id, catCount: craft.entries.relatedTo(cat).total()  }
    ] %}

    {% set catObjects = catObjects|merge(catObject) %}

{% endfor %}