php array - how to insert preserving the sorting order ?

Posted on 2011-05-11
Last Modified: 2012-05-11
I have an array of ISBNS which I would like to be sorted
when I put a  new ISBN, how to insert it to preserve a sorting order
Question by:Rozamunda
    LVL 15

    Accepted Solution

    How do you want to sort array?  By key or by elements
    First add array
    $newval = array (2331, 232322,3434343);
    array_push ($newval ,312126);  // we are adding four more elements to the array 

    Open in new window

    Now Choose your sorting option:
    asort(); //elements sort ascending
    arsort(); //elements sort descending;
    ksort();//by  key sort ascending;
    krsort(); //by key sort descending;

    Open in new window

    LVL 1

    Expert Comment

    Thank you. This is also my problem. It's easy for understanding.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to dynamically set the form action using jQuery.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now