title: sorted array in php
body: <p>in many languages like c#, java, etc, we have sorted array! it mean when we add some element to it, it will add new element in correct index base on sorting method ...
  with this algorithm inserting and element is too fast !</p>
  <p>but in php as i know, we can just sort array with ksort,sort or something like that and i did't find something like sorted array in php for better performance in managing one array that we want always be sorted!</p>
  <p>in my tough if i figure out how ksort works, i could write sorted array myself but i did't find any solution to add item to array by index ...</p>
  <p>does anyone know how to implement sorted array in php ? Or
  does anyone know how to add element in any index i want?</p>
  <hr />
  <p>update 1</p>
  <p>i need something like this in php : <a href="https://www.tutorialsteacher.com/csharp/csharp-sortedlist" rel="nofollow noreferrer">https://www.tutorialsteacher.com/csharp/csharp-sortedlist</a></p>
  <p>i have huge array (about 2m rows) and i should keep it sorted base on something like price !</p>
  <p>for now i sorting it by <code>ksort</code> but i cause me huge impact on performance</p>
  <hr />
  <p>Update 2</p>
  <p>i want to create trade matching engine for my crypto currency exchange and for now i using redis as my data entry but when i used in php array as my data entry, performance increase about 250x.</p>
  <p>(in redis i can add orders about 3.5k/s)</p>
  <p>i tested my code and figured out that <code>ksrot</code> take about 83% of my code runtime. now i want to use sorted list as i say for improving my performance. for now i can handle about 930k/s orders(add in array , sort array, iterate top of array) with <code>ksort</code>.</p>