I have a dilemma. Because I'm using Amazon's MWS, I have to get the order of the array exactly as Amazon would before I hash the contents otherwise the hash that I make and the hash Amazon makes won't match and Amazon won't accept my feed.
While I know of PHP's usort I've never used it, so I'm not sure quite how to create a function that does what I need.
Here's the array:
Array (
[0] => AWSAccessKeyId=XXXXXXXX
[1] => Action=ListInventorySupply
[2] => MarketplaceId=XXXXXXX
[3] => ResponseGroup=Basic
[4] => SellerId=XXXXXX
[5] => SellerSkus.member.10=SKU10
[6] => SellerSkus.member.11=SKU11
[7] => SellerSkus.member.1=SKU1
[8] => SellerSkus.member.2=SKU2
[9] => SellerSkus.member.3=SKU3
[10] => SellerSkus.member.4=SKU4
[11] => SellerSkus.member.5=SKU5
[12] => SellerSkus.member.6=SKU6
[13] => SellerSkus.member.7=SKU7
[14] => SellerSkus.member.8=SKU8
[15] => SellerSkus.member.9=SKU9
[16] => SignatureMethod=HmacSHA256
[17] => SignatureVersion=2
[18] => Timestamp=2016-04-06T22%3A26%3A41Z
[19] => Version=2010-10-01
)
The problem is that Amazon's sort is just slightly different:
Array (
[0] => AWSAccessKeyId=XXXXXXXX
[1] => Action=ListInventorySupply
[2] => MarketplaceId=XXXXXXX
[3] => ResponseGroup=Basic
[4] => SellerId=XXXXXX
[5] => SellerSkus.member.1=SKU1
[6] => SellerSkus.member.10=SKU10
[7] => SellerSkus.member.11=SKU11
[8] => SellerSkus.member.2=SKU2
[9] => SellerSkus.member.3=SKU3
[10] => SellerSkus.member.4=SKU4
[11] => SellerSkus.member.5=SKU5
[12] => SellerSkus.member.6=SKU6
[13] => SellerSkus.member.7=SKU7
[14] => SellerSkus.member.8=SKU8
[15] => SellerSkus.member.9=SKU9
[16] => SignatureMethod=HmacSHA256
[17] => SignatureVersion=2
[18] => Timestamp=2016-04-06T22%3A26%3A41Z
[19] => Version=2010-10-01
)
You'll see that the keys for the first three SellerSkus.member.{#} elements are different. I need to be able to keep the remaining sort the same, except that when there are 10 or more SKU's it needs to sort like Amazon's sort.
I've read the PHP doc for usort, but I'm still not getting anything that works above 10 items. It seems like I have to keep track of the SellerSkus.member.{#} number, in order to sort them correctly, but I haven't the foggiest idea of how to do that with usort. Any guidance in the right direction would be awesome! Thanks.
natsort, it finds the numeric part of the string and sorts it numerically.natsorttakes those elementsSellerSkus.member.10&SellerSkus.member.11and places them behind the elementSellerSkus.member.9. What's strange is that on thenatsortpage, it shows a "Standard sorting" section that sorts the values just as I need it, however, that's not howsortor evenasortis actually sorting the array.