I have 2 arrays

```
Array 1 : $agents = Array('abc','xyz','pqr');
Array 2 : $tot_calls = Array ('10','5','20');
```

Here array 2 reflects total calls made by agents in $agents array respectively. i.e Agent abc made 10 calls , Agent xyz made 5 calls and so on.

I want the resultant array to display agents sorted(DESCENDING) by the number of calls they made

i.e `$result = Array('pqr','abc','xyz');`

// Here the resulting array is sorted on the max calls they made.

You can combine `array_combine()`

the `krsort()`

on this particular situation. Consider this example:

```
$agents = Array('abc','xyz','pqr');
$tot_calls = Array ('10','5','20');
// calls become the keys and agents become the values
$sorted_values = array_combine($tot_calls, $agents);
krsort($sorted_values); // sort them by keys
print_r($sorted_values);
// maybe if you want to clear the keys
$sorted_values = array_values($sorted_values);
```

EDIT:

Alternatively, @Satish made a good point about it. To avoid the same key issue (well maybe, at least if there are no agent name collision). You can use this instead (just the other way around):

```
$agents = Array('abc','xyz','pqr');
$tot_calls = Array ('10','5','20');
// agents become keys and calls become values
$sorted_values = array_combine($agents, $tot_calls);
arsort($sorted_values);
$sorted_values = array_keys($sorted_values);
print_r($sorted_values);
```

try this

```
$agents = Array('abc','xyz','pqr');
$tot_calls = Array (10, 5, 20);
arsort($tot_calls);
foreach($tot_calls as $key=>$val)
{
$arr_agents[] = $agents[$key];
}
print_r($arr_agents);
```

**OUTPUT :**

```
Array
(
[0] => pqr
[1] => abc
[2] => xyz
)
```

**DEMO-2 :** with

```
$agents = Array('abc','xyz','pqr','lmn');
$tot_calls = Array ('10', '5', '20', '5');
```

**OUTPUT-2:**

```
Array
(
[0] => pqr
[1] => abc
[2] => lmn
[3] => xyz
)
```

Similar Questions

I'm trying to write an algorithm that will return True/False whether a contiguous sequence in a sorted array that contains only positive integers, can sum up to N. For example: Array = { 1, 2, 3, 4 };

I have an array that looks like this: Array ( [0] => Dog:110 [1] => Cat:111 [2] => Mouse:101 ) Based on that array, I want to create another array to look like this Array ( [Dog] => 110 [

the question is simple: there is some way that the ordered array that returns me the qsort, is returned in reverse, ie I want to avoid the use of any auxiliary array to invest the resulting array us

In c++, std::set which stores its element in sorted order can insert elements in O(log n) time. But all the methods i know take linear time: Inserting the element at the end of the array and swapping

Given an array of integers, I would like to find the minimum number x such that increasing or decreasing the elements in the array by a number in the range of 0 to x will result in an array sorted in

Suppose I have two arrays that look like this: ('1', '6', '8', '4', '5') ('a', 'c', 'd', 'f', 'w') I want to sort the first array, and the order of elements in the second array should change in the s

I want to sort my initial array(s) that contain many keys and values inside, into array(s) sorted by a specific key, and all the values for that key in a single array based on the key. So here's the a

Suppose given an array of size n, with sorted values. In iteration i, a new random-generated value is given, and inserted into the end of the array. The array is then resorted, and discard the least

I recently faced a programming problem which is as follows: A sorted array is given and the array is rotated at some unknown point, I have to find the minimum element in it. The Array can contain dupl

Is there a way to turn a Binary to a sorted array without having to traverse the tree for every array index? Node root; Node runner; int current_smallest; void findsmallest(Node root){ //Pre-order tra

This is an interview question: given an integer x and a sorted array a[] of N distinct integers, design a linear-time algorithm to determine if there exists two distinct indices i and j such that a[i]

How do I put values from a sorted list and array into a dictionary and determine how many time numbers repeat themselves? This is my code so far. from numpy import * from random import * lista=[] for

I just want to iterate through an image array one by one but I can't get it working, I get the errors below. I can show single images via imshow (a), but not iterate through an array. Error using getI

Trying to arrange an array based on the order of another array function Sort(old, new){ var temp = []; for(var i=0; i<old.length; i++){ temp[i] = old[new[i]]; } return temp; } Is it possible to ac

Please check this Fiddle: http://jsfiddle.net/houmaka/vHXy4/ When user fills different fields ng-repeat order the output. How can I enforce a custom ordering based on my fields array? (There are more

I have an array full of dynamic <select> field options, that I would like to be split into separate arrays based on a certain value within each loop. Basically, I'd like two arrays: one with t

I need to print an array with menu items in 4 columns, sorted vertically, and filled out like this: Here's the markup structure to follow (5 items). <ul> <li>1</li> <li>2</

I'm working on a problem in C, and I have a quick question about it. The problem is as follows: I'm given some sorted array of integers, say, a[i] = { 1, 2, 3, 3, 3 }. Now, I am supposed to run a prog

I am trying to build a program that accepts an array of integers as parameter and return a string. The string would be ascending if the array is sorted from the smallest to the greatest, descending

so I have two arrays. one of them looks like this (it's values or the number of elements can change): array('4dec' , 'def3', 'a3d6', 'd12f'); and the other: array(array('id' => 'd12f', 'name' =>

I'm working on sorted Queues like a Priority Queue. I already did it with a List, and it already worked great. Now I'd like to do it with a array. But I have a little logical Problem with add a new El

Given an array a[], what would be the most efficient way to determine whether or not at least one element i satisfies the condition a[i] == i? All the elements in the array are sorted and distinct, bu

I have a list of objects: [ { id: 4, name:'alex' }, { id: 3, name:'jess' }, { id: 9, name:'...' }, { id: 1, name:'abc' } ] I have another list with the right order. [ 3, 1, 9, 4] How can I match t

I have two dropdownlistfor, and the second of them should be filled with an array based on the value of the first dropdownlist I've tried to follow Darins Answer here but I have problem getting the se

Yet another interview question asked me to find the maximum possible subarray of repeated values given a sorted array in shortest computational time possible. Let input array be A[1 ... n] Find an arr

I have an array from a plist and each value contains an key and a string and a secondary array that I get from a json file online. I want to order the secondary array based on the keys in the first ar

We have two arrays as input Array1: [7,12,11,4] Array2:[1,3,2,0] --> This is the index array(i.e positions of Array1 if it is sorted). Now we need to sort Array1 using index array Array2. Time comp

i have coded an algorithm for search in sorted array with complexity log2(n)/5 .Is it useful?

I have an array that looks like this: ( { title = Chris; isMale = 1; age = 13; }, { defaultTitle = Jessica; isMale = 0; age = 15; } ) I want to create another array that contains the dictionaries

I am using the twig templating engine. I basically have an array looping through resources which is fine however I have added another array within it which has a key, based on the loop index in the to

Given a Sorted Array which can be rotated find an Element in it in minimum Time Complexity. eg : Array contents can be [8, 1, 2, 3, 4, 5]. Assume you search 8 in it.

I have this array: $categories = array( array('id' => 1, 'parent' => 0, 'name' => 'Category A'), array('id' => 2, 'parent' => 0, 'name' => 'Category B'), array('id' => 3, 'parent'

On sorting an array i get : 1,10,2,3,4,5,6,7,8,9. What went wrong ? My code was: NSArray *sortedArray = [optionKeys sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; where optio

How do I add one array into another one? The problem is that I insert this array several times in different slots, but the array I insert changes, so I get a array with every field looking the same.

I am trying to create an application which find near by restaurants, I have used a database to retrieve near by zipcodes so I now have an array like $sortLike=array(60007,60001,60003,60002); and data

Is it possible to sort and rearrange an array that looks like this: itemsArray = [ ['Anne', 'a'], ['Bob', 'b'], ['Henry', 'b'], ['Andrew', 'd'], ['Jason', 'c'], ['Thomas', 'b'] ] to match the arrange

we got an increasing sorted multidimensional array for example: int[][] mat = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}, {13,14,15,16}}; How can I use binary search to find a specific number? let's say im

This is an interview question. Given a sorted integer array and number z find all pairs (x, y) in the array so that x + y < z. Can it be done better than O(n^2)? P.S. I know that we can find all pa

What is the more efficient way to insert an array inside another array. a1 = [1,2,3,4,5]; a2 = [21,22]; newArray - a1.insertAt(2,a2) -> [1,2, 21,22, 3,4,5]; Iterating a2 using splice looks a bit

I have an assignment for school where the user has to input numbers and the program has to determine whether they are sorted or not. If anyone can help with my code that would be awesome. I am having

I have create to String array one is word another is sentence. <resources> <string-array name=word> <item> the</item> <item> a</item> <item> is</ite

I'm attempting to perform a simple task: append an array to the beginning of another array. Here a MWE of what I mean: a = ['a','b','c','d','e','f','g','h','i'] b = [6,4,1.,2,8,784.,43,6.,2] c = [8,4.

Possible Duplicate: PHP - sort an array based on another array? Need some help regarding array sorting.... I have two arrays. The main one (where the key is the user id) : $user[31] = 'Tom' $user[43

I have the following array that I need to have sorted from highest score to lowest. Array ( [0] => Array ( [team id] => 5 [score] => 52 [fouls] => 0 ) [1] => Array ( [team id] => 4 [

I have an array of ints, they need to be grouped by 4 each. I'd also like to select them based on another criterion, start < t < stop. I tried data[group].reshape((-1,4))[start < t < stop]

I am trying to find out if the array a user inputs is sorted or not (not trying to sort it though). If the user's input is in ascending order from least to greatest, I want to write a message saying

I have an array of objects (all the same object type). I have another array of the same object type in which I want to use to tell me which objects to delete from the first array. Is there an easy way

I am trying to display my array contents in a UITextView. This should be simple. The array echoes using NSlog ( ( Point 1, Point 2, Point3 ) ) using the following doesn't work as I know the array

I have an array with values as follows: 0-10 10-50 50-100 100-150 150-200 200+ This is actually an array of WordPress taxonomies, which WP sorts alphabetically (or ascending order of the first digit)

here i have wrote code for finding median of two sorted array #include<iostream> using namespace std; #define L 5 #define M 6 const int N=L+M; int A[1000];//define 1 indexed aarray int B[1000];