Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8450757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:03:36+00:00 2026-06-10T11:03:36+00:00

I never thought I would have to ask this… I need a way to

  • 0

I never thought I would have to ask this… I need a way to mimic PHP’s ksort function in C#.

Here’s the problem… PHP does this…

PHP CODE

$arr = array(
    "tagValues" => "asdfasd",
    "email" => "asdfasd",
    "referrer" => "asdfasd",
    "tags" => "asdfasd",
);

echo "Base array \n\n";
print_r($arr);

ksort($arr);

echo "\n\nksort'ed array \n\n";
print_r($arr);

PHP OUTPUT

Base array 

Array
(
    [tagValues] => asdfasd
    [email] => asdfasd
    [referrer] => asdfasd
    [tags] => asdfasd
)


ksort'ed array 

Array
(
    [email] => asdfasd
    [referrer] => asdfasd
    [tagValues] => asdfasd
    [tags] => asdfasd
)

While if I do this in C#…

string[] sortedKeys = form.AllKeys.OrderBy(x => x).ToArray();

It comes out in a different order. tags will be before tagValues, as it rightfully should be. That is the true alphabetically order.

It’s my understanding that ksort does some kind of case-sensitive ASCII work on the array and that’s why it comes out in a different order.

How can I implement that in C#? Preferably with LINQ. Thanks!

For those interest in the backstory…

I’m basically trying to create an MD5 hash of input parameters sorted in alpha order per the FastSpring API. Their PHP snippet operates differently than I expected when I translated to C#, so the hash is always incorrect.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:03:37+00:00Added an answer on June 10, 2026 at 11:03 am

    Keyword is StringComparer.Ordinal

    string[] sortedKeys= form.AllKeys.OrderBy(x => x,StringComparer.Ordinal).ToArray();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Never thought I'd have this problem :) The following snippet of code works in
Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {
I have zero experience with COM. I actually never thought, I'll need to do
I have never used threads--never thought my code would benefit. However, I think threading
I would never have considered using window.opener to call a javascript function in the
I do not currently have this issue , but you never know, and thought
I have never thought about until recently, but I'm not sure why we call
When this quick one hour project came up I never thought that 2 days
I never thought I would be asking such a simple question but how do
I would have thought that there is a lot of information out there on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.