berridgeab Posted May 15, 2008 Share Posted May 15, 2008 Hi I got a problem, I have two arrays: - $PartsArray = array(806890591, 806890386, 806890578); //Array One with some example values (Part numbers) $QtyArray = array(10, 12, 2); //Array two with some example Quantities (Quantites of Part numbers) In one array I have Part numbers/ product codes. In the other array there are the quantites of each part number. They are both filled Incremently so: - 806890591 = Qty 10 or in other words $PartsArray[0] relates to $QtyArray[0] $PartsArray[1] relates to $QtyArray[1] etc etc etc What I need to do is put the Data within $QtyArray in Highest Order, i.e so it reads: - 12 10 2 However, when outputting, I also need to maintain which Qty relates to which part number. If I ran a simple sort on the $QtyArray, it would result in 12 = 806890591 10 = 806890386 2 = 806890578 Obviously, this messes up the way the part numbers relate to the Qty, is there any way of me Sorting the $QtyArray whilst still retaining a relationship with the $PartsArray? Basically I want PHP to output the page like this: - 12 = 806890386 10 = 806890591 2 = 806890578 This will be done with 25 'top' selling parts once I have it finished, I just can't figure out how to list it the way I want. I feel it's something to do with the Array function asort(); but not too sure on how to implement it. Any ideas? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 15, 2008 Share Posted May 15, 2008 What's your problem? Ken Quote Link to comment Share on other sites More sharing options...
berridgeab Posted May 15, 2008 Author Share Posted May 15, 2008 Sorry hit enter too early, have editted first post to relfect what I need help with, thanks. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 15, 2008 Share Posted May 15, 2008 I believe you want to do something like this: <?php $PartsArray = array(806890591, 806890386, 806890578); //Array One with some example values (Part numbers) $QtyArray = array(10, 12, 2); $new = array_combine($QtyArray,$PartsArray); echo '<pre>' . print_r($new,true) . '</pre>'; krsort($new); echo '<pre>' . print_r($new,true) . '</pre>'; ?> Ken Quote Link to comment Share on other sites More sharing options...
berridgeab Posted May 15, 2008 Author Share Posted May 15, 2008 That's perfect, thanks for your rapid response. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.