Note that there are some explanatory texts on larger screens.

plurals
  1. POBest way of building a collection of unique ID's as well as their counts
    primarykey
    data
    text
    <p>I've looked into various different ways of array's, arraylist's, dictionaries... but as I'm used to PHP I'm not entirely sure on the best way I could collect the following information.</p> <p>My program loops through each user, and if their is a location ID, I want to add that to some sort of collection / array. It's expected that different users will have the same location ID.</p> <p>If the location ID is the same, I need to increase an integer of how many occurrence for that location ID.</p> <p>Example:</p> <pre><code>User1 - Location1 User2 - Location3 User3 - Location3 Location1 = 1 Location3 = 2 </code></pre> <p><strong>Also</strong> I need to somehow append each user ID to this collection. So Location3 / 2 occurrences / user2/user3</p> <p>I've been trying to figure out the best way of doing this for about two hours now, and all the different methods of multidimensional arrays, arraylists, dictionaries is all a little confusing as it all seems abstract to my PHP knowledge. I think C# handles arrays in an entirely different way.</p> <p>Essentially, the collection with unique location ID's / occurrences / and users collection needs to be stored in something that can be passed to somewhere else in my program as an argument.</p> <p><strong>I've made a PHP script which does exactly what I'm after</strong></p> <pre><code>foreach($call["data"] as $v) { // Foreach USER ($v containing their unique ID and location ID.) $user_id = $v["id"]; $location_id = $v["location"]["id"]; // This adds the location ID as the key within the array, followed by every user who has it. I don't need a count in this case, as I could just count the number of users. $collection[$location_id][$user_id] = null; } </code></pre> <p>This in return creates this array when printed using print_r</p> <pre><code>[106078429431815] =&gt; Array ( [620790873] =&gt; [626276302] =&gt; [100000152470577] =&gt; ) </code></pre> <p>(Small part of the output). - Added PHP Example. Anyone know how I can get C# to collect the same information in the same way my PHP array does?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload