In my website, users can publish their profile in different languages, something like LinkedIn, now we're searching between firstname of users, for example we search for: 'ar' and we look into all profiles languages, we will have an array in return like:
array
0 => string '20=>en' (length=5)
1 => string '42=>en' (length=5)
2 => string '20=>fa' (length=5)
3 => string '42=>sp' (length=5)
4 => string '12=>fr' (length=5)
5 => string '83=>ar' (length=5)
6 => string '160=>sp' (length=5)
The above array shows that we've got 6 profiles which matches our search 'ar' in different languages, the above array says:
0 => Match found for User with ID = 20 in English Lang(en) profile
1 => Match found for User with ID = 42 in English Lang(en) profile
2 => Match found for User with ID = 20 in Farsi Lang(fa) profile
3 => Match found for User with ID = 42 in Spanish Lang(sp) profile
4 => Match found for User with ID = 12 in French Lang(fr) profile
5 => Match found for User with ID = 83 in Arabic Lang(ar) profile
6 => Match found for User with ID = 160 in Spanish Lang(sp) profile
Now, we want to show the results, but as a matter of fact, as you see in the results, we've got matches for 'ar' for the user with ID = 20 in Both English and Farsi languages, but we can't show 2 results of the same person! so we need to let go of the axillary results, so the array above should be filtered and uniqued based by user IDs and priority of the languages, my priority for the languages is:
- $_SESSION['my_lang'];
- English Language (en);
- Rand();
The person who enters 'ar' as his search query has a $_SESSION['my_lang'], so in the results array for the user which has results in $_SESSION['my_lang'] we should keep that results and let go of the other matches for the same person.
After $_SESSION['my_lang'], our priority should be EN lang, if a person has results in N languages, but we could not found the match in $_SESSION['my_lang'], then we should keep the results in en lang and clear the rest of results for that person.
after the above priorities, actually nothing matters, we just need to keep one of the results for that person and get rid of other results for that person, so the languages should be selected randomly...
I have no idea how this could be accomplished, I would appreciate any kind of help.
In my example, I have an array like:
array
0 => string '20=>en' (length=5)
1 => string '42=>en' (length=5)
2 => string '20=>fa' (length=5)
3 => string '42=>sp' (length=5)
4 => string '12=>fr' (length=5)
5 => string '83=>ar' (length=5)
6 => string '160=>sp' (length=5)
but in your example, you have an array like:
$users = array(
array('id'=> 20, 'lang'=>'en'),
array('id'=> 42, 'lang'=>'en'),
array('id'=> 20, 'lang'=>'fa'),
array('id'=> 42, 'lang'=>'sp'),
array('id'=> 12, 'lang'=>'fr'),
array('id'=> 83, 'lang'=>'ar'),
array('id'=> 160, 'lang'=>'sp'));
How should I make my array to look like your array, so your codes work..? Thanks