Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
Create hash for array irrespective of element order

If I have an array with two elements that I want to sha1 hash, what would be the best way to hash irrespective of the order of the elements. This problem also applies for larger arrays and multidimensional arrays.

So [a=1,b=2] and [b=2,a=1] will return the same hash.

node.js has Object-Hash that does exactly this for example.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Sort the array by keys, then serialize it, then hash that.

ksort($array);
$hash = sha1(serialize($array));
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!