Thursday 29 April 2010

Explain sort(), rsort(), asort(), arsort(), ksort(), krsort() and natsort()?

Suppose we have an array like below:

$fruits = array("lemon""orange""banana""apple");

1. sort()       
This function sorts an array. Elements will be arranged from lowest to highest when this function has completed.
e.g.,
sort($fruits);

The above example will output:
fruits[0] = apple
fruits[1] = banana
fruits[2] = lemon
fruits[3] = orange 


2. rsort()            
This function sorts an array in reverse order (highest to lowest).
Note: This function assigns new keys for the elements in array. It will remove any existing keys you may have assigned, rather than just reordering the keys.
 e.g.,
rsort($fruits);


The above example will output:
0 = orange
1 = lemon
2 = banana
3 = apple


3. asort()              
This function sorts an array such that array indices maintain their correlation with the array elements they are associated with. This is used mainly when sorting associative arrays where the actual element order is significant.
e.g.,
asort($fruits);

The above example will output:
c = apple
b = banana
d = lemon
a = orange

4. arsort()               
This function sorts an array such that array indices maintain their correlation with the array elements they are associated with. This is used mainly when sorting associative arrays where the actual element order is significant.
e.g.,
arsort($fruits);

The above example will output:
a = orange
d = lemon
b = banana
c = apple
 
5. ksort()
               Sorts an array by key, maintaining key to data correlations. This is useful mainly for associative arrays.
e.g.,
ksort($fruits);

The above example will output:
a = orange
b = banana
c = apple
d = lemon

6. krsort()               
Sorts an array by key in reverse order, maintaining key to data correlations. This is useful mainly for associative arrays.
e.g.,
krsort($fruits);

The above example will output:
d = lemon
c = apple
b = banana
a = orange
 
7. natsort()
                 This function implements a sort algorithm that orders alphanumeric strings in the way a human being would while maintaining key/value associations. This is described as a "natural ordering".

e.g., 
<?php
$array1 
$array2 = array("img12.png""img10.png""img2.png""img1.png");
sort($array1);
echo 
"Standard sorting\n";print_r($array1);
natsort($array2);
echo 
"\nNatural order sorting\n";print_r($array2);?>  


The above example will output:
Standard sorting
Array
(
    [0] => img1.png
    [1] => img10.png
    [2] => img12.png
    [3] => img2.png
)

Natural order sorting
Array
(
    [3] => img1.png
    [2] => img2.png
    [1] => img10.png
    [0] => img12.png
)



Cheers!





93 comments:

  1. hey alex! no there is no date sort function in php. php does not have built - in function for the same. but you can do with uksort function. example given below:

    'some text', '2008-03-06' => 'some text');

    function cmp($a, $b)
    {
    global $array;
    return strcmp($array[$a]['db'], $array[$b]['db']);
    }

    uksort($array, 'cmp');

    print_r($array);
    ?>

    ReplyDelete
  2. nice sorting fun

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. After reading this blog i am very strong and clear in this topic.. explanation are step by step so easy to understand

    php training institute | best php training institute | best php training institute in chennai | php training institute in chennai

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. krsort is just what i needed

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. Good Blogpost. Really helpful information thanks for this post. keep continue the same thing. learn PHP training in Bangalore

    ReplyDelete
  9. Wow! That's really great information guys.I know lot of new things here. Really great contribution.Thank you ...

    mulesoft training course

    ReplyDelete
  10. eish ❤, make things look simple. i loved your simplification of those functions now i am able to apply where necessary.be blessed with good work

    ReplyDelete
  11. We've tried and investigated more than 10 triathlon suits to pick the best. These rankings are the zenith of our endeavors. Which is the Best Tri Suit? Pick the best triathlon suit for preparing and hustling. Best Tri Suit

    ReplyDelete
  12. Ordinarily, running and cycling are kept on the rundown before hitting the icy waters. After you hit the waters, it makes the Best Tri Suit wet and accordingly it kept generally at the remainder of the marathon. Best Tri Suit Online

    ReplyDelete
  13. Existing without the answers to the difficulties you’ve sorted out through this guide is a critical case, as well as the kind which could have badly affected my entire career if I had not discovered your website.

    java training in omr

    java training in annanagar

    java training in chennai

    java training in marathahalli

    java training in btm layout

    java training in rajaji nagar

    java training in jayanagar

    ReplyDelete
  14. A good blog always comes-up with new and exciting information and while reading I have feel that this blog is really have all those quality that qualify a blog to be a one.I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts read this.
    Big data training in Velachery
    Big data training in Marathahalli
    Big data training in btm
    Big data training in Rajajinagar
    Big data training in bangalore

    ReplyDelete
  15. Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us

    MEAN stack training in Chennai
    MEAN stack training in bangalore
    MEAN stack training in tambaram
    MEAN stack training in annanagar

    ReplyDelete
  16. From your discussion I have understood that which will be better for me and which is easy to use. Really, I have liked your brilliant discussion. I will comThis is great helping material for every one visitor. You have done a great responsible person. i want to say thanks owner of this blog.
    python training in annanagar | python training in chennai

    python training in marathahalli | python training in btm layout

    python training in rajaji nagar | python training in jayanagar

    ReplyDelete
  17. Were a gaggle of volunteers as well as starting off a brand new gumption within a community. Your blog furnished us precious details to be effective on. You've got completed any amazing work!
    java training in chennai | java training in bangalore

    java online training | java training in pune

    java training in chennai | java training in bangalore

    ReplyDelete
  18. Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.

    rpa training in marathahalli

    rpa training in btm

    rpa training in kalyan nagar

    rpa training in electronic city

    rpa training in chennai

    rpa training in pune

    rpa online training

    ReplyDelete
  19. This comment has been removed by the author.

    ReplyDelete
  20. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog. 

    Python training in marathahalli
    Python training in pune

    ReplyDelete
  21. This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.. 
    python training in rajajinagar
    Python training in btm
    Python training in usa

    ReplyDelete
  22. Thanks for your informative article, Your post helped me to understand the future and career prospects & Keep on updating your blog with such awesome article.
    Python training in usa
    Python training in marathahalli
    Python training in pune

    ReplyDelete
  23. Some us know all relating to the compelling medium you present powerful steps on this blog and therefore strongly encourage contribution from other ones on this subject while our own child is truly discovering a great deal. Have fun with the remaining portion of the year.
    Python training in pune
    AWS Training in chennai
    Python course in chennai
    Python training institute in chennai

    ReplyDelete
  24. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    Online IT Training Videos

    Microsoft Azure Training Videos

    SCCM Training Videos

    Office 365 Training Videos

    ReplyDelete
  25. This is such a great post, and was thinking much the same myself. Another great update.
    SAP QM Training

    SAP SD Training

    SAP Security Training

    SAP XI/PI Training

    ReplyDelete
  26. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
    Best Selenium Training in Chennai | Selenium Training Institute in Chennai | Besant Technologies


    ReplyDelete
  27. Howdy, would you mind letting me know which web host you’re utilizing? I’ve loaded your blog in 3 completely different web browsers, and I must say this blog loads a lot quicker than most. Can you suggest a good internet hosting provider at a reasonable price?


    Best AWS Training Institute in BTM Layout Bangalore ,AWS Coursesin BTM


    Best AWS Training in Marathahalli | AWS Training in Marathahalli

    Amazon Web Services Training in Jaya Nagar | Best AWS Training in Jaya Nagar


    ReplyDelete
  28. Great blog!!! It was very impressed to me. I like so much and keep sharing. Thank you.

    reviewcouncil
    Article submission sites

    ReplyDelete
  29. Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me
    Data Science course in kalyan nagar
    Data Science course in OMR
    Data Science course in chennai
    Data science course in velachery
    Data science course in jaya nagar
    Data Science interview questions and answers

    ReplyDelete
  30. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.
    Most of ideas can be nice content.The people to give them a good shake to get your point and across the command.
    data science online training
    python online training
    uipath online training
    data science with python online training
    rpa online training

    ReplyDelete
  31. Its really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing....
    devops online training

    aws online training

    data science with python online training

    data science online training

    rpa online training

    ReplyDelete
  32. Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point.
    Microsoft Azure online training
    Selenium online training
    Java online training
    uipath online training
    Python online training

    ReplyDelete

  33. Hello, I read your blog occasionally, and I own a similar one, and I was just wondering if you get a lot of spam remarks? If so how do you stop it, any plugin or anything you can advise? I get so much lately it’s driving me insane, so any assistance is very much appreciated.
    Android Course Training in Chennai | Best Android Training in Chennai
    Best Data Science Course Training in Chennai | Best Data Science Training in Chennai
    Matlab Training in Chennai | Best Matlab Course Training in Chennai
    AWS Training in Chennai | AWS Training Course in Chennai

    ReplyDelete
  34. QuickBooks Payroll Support Phone Number management quite definitely easier for accounting professionals. There are plenty individuals who are giving positive feedback when they process payroll either QB desktop and online options.

    ReplyDelete
  35. If this doesn’t help you, go ahead and connect to us at
    QuickBooks Help & Support. The majority of us works 24*7 and serve its customers with excellent service each time they e mail us. It doesn't matter what issue is and however complex it truly is, we assure you that individuals offers you optimal solution as quickly as possible.

    ReplyDelete
  36. We're going to also provide you with the figure of your respective budget which you can be in the near future from now. This is only possible with QuickBooks Support Phone Number

    ReplyDelete
  37. security of the vital business documents. QuickBooks Tech Support Phone Number now have a propensity to never compromise using the safety of one's customers. You’ll manage to give us a call any time for the moment support we have a tendency to are accessible for you personally 24*7.

    ReplyDelete
  38. Feel free to anytime 27×7 contact us the QB help desk number and fixing all types of issue within a short span .
    QuickBooks is rated business accounting software and the minute query or issue troubling you do not panic, call the Quickbooks Support Number. The Intuit certified technician called Proadviors can assist & help you to sort out any errors , problem .

    ReplyDelete
  39. Manufacturing & Wholesale: probably the most exemplary QuickBooks Enterprise support Number versions, Enterprises plays a vital role in carrying out the manufacturing & wholesale business.

    ReplyDelete
  40. Unneeded to state, QuickBooks Tech Support Phone Number has given its utmost support to entrepreneurs in decreasing the price otherwise we’ve seen earlier, however, an accountant wont to keep very different accounting record files.

    ReplyDelete
  41. QuickBooks software package is developed in such a manner that it will provide you with the best account management reference to this era. However, you might face the matter along with your QuickBooks Tech Support Phone Number software and start looking for the solution.

    ReplyDelete
  42. Inuit has surely made inventory management an invaluable feature associated with the QuickBooks. Because the user can quickly cope with vendors and wholesalers and payment (pending or advance) linked to vendors and wholesalers. Our QuickBooks Customer Support Number team will surely there for you to guide and help you in inventory management.

    ReplyDelete
  43. The above mentioned steps will solve the script issue for sure. If not, Get technical help from our technicians available on just a call at our toll-free.We are fully invested in our highest quality technical support services without compromising with your quality standards. A QuickBooks Support Phone Number, we offer the finest and the most optimal solution each and every issue along with the reliable technical assistance in QuickBooks from installation to functionality.

    ReplyDelete
  44. Why you ought to choose QuickBooks Customer Support Phone Number The principal intent behind QuickBooks Support number would be to give you the technical help 24*7 so as with order in order to prevent wasting your productivity hours. It is completely a toll-free QuickBooks client Service

    ReplyDelete
  45. Could you run a company? Would it be too hard to deal with all? You may need a hand for support. Quickbooks Support is a remedy. If you wish to accomplish that through QuickBooks, you get several advantages. Today, payroll running is currently complex. You might need advanced software. There should be a premier mix solution.

    ReplyDelete
  46. In May 2002 Intuit thrown QuickBooks Enterprise Solutions for medium-sized businesses. QuickBooks Enterprise Support Number here to make tech support team to users. In September 2005, QuickBooks acquired 74% share related to market in the united states. A June 19, 2008 Intuit Press Announcement said that at the time of March 2008, QuickBooks’ share of retail units inside the industry accounting group touched 94.2 percent, based on NPD Group.

    ReplyDelete
  47. Any QuickBooks user faces any sort of identified errors in their daily accounting routine; these errors may differ from 1 another to a large degree, so our dedicated QuickBooks Enterprise Support Phone Number Pro-Advisers are very well loaded with their tools and expertise to give most effective resolutions very quickly to the customers.

    ReplyDelete
  48. QuickBooks Enterprise Support contact number is assisted by an organization this is certainly totally dependable. It is a favorite proven fact that QucikBooks Enterprise Enterprise Technical Support

    ReplyDelete
  49. QuickBooks has made payroll management quite definitely easier for accounting professionals. There are so many individuals who are giving positive feedback if they process payroll either QB desktop and online options. In this internet site, we are going to enable you to experience to make and place up the checklist for employee payment. To have more enhanced results and optimized benefits, you are able to take the help of experts making a call at QuickBooks Payroll Tech Support Number. Well! If you’re not in a position to customize employee payroll in Quickbooks while making the list optimally, in QB and QB desktop, then browse the description ahead. Here, you receive the determination of numerous kind of information what you’ve close by for assisting the setup process with comfort.

    ReplyDelete
  50. You can go to the official website of QuickBooks from where you can be able to download the original version of the QuickBooks Upgrade Support Phone Number software.

    ReplyDelete
  51. QuickBooks Enterprise customer support cell phone number. We understand that your growing business needs your precious time which explains why QuickBooks Enterprise Support Phone Number the most effective to the customers.

    ReplyDelete
  52. Maybe you have trapped into a problem with Intuit product and payroll services? You might be happy to understand the best approach to get hold of the consumer support team by dialing QuickBooks Payroll Tech Support Number. AccountWizy welcome you 24*7 to gain access to the different support services of Intuit products asking for QuickBooks enhanced payroll support.

    ReplyDelete
  53. You should use QuickBooks to come up with any selection of reports you wish, keeping entries for many sales, banking transactions and plenty of additional. QuickBook Support Phone Number provides an array of options and support services for an equivalent.

    ReplyDelete
  54. How to contact QuickBooks Payroll support?
    Different styles of queries or QuickBooks related issue, then you're way in the right direction. You simply give single ring at our toll-free intuit Phone Number for QuickBooks Payroll Supportt . we are going to help you right solution according to your issue. We work on the internet and can get rid of the technical problems via remote access not only is it soon seeing that problem occurs we shall fix the same.

    ReplyDelete
  55. It's simple to get a quantity of benefits with QuickBooks Tech Support Number. Proper analyses are done first. The experts find out from the nature associated with trouble. You'll get a whole knowledge as well. The support specialist will identify the problem. The deep real cause will probably be found out. All the clients are extremely content with us.

    ReplyDelete
  56. QuickBooks Support Phone Number includes support to every other product of QuickBooks, including Payroll services, QuickBooks Mac Desktop, QuickBooks POS and Payments.

    ReplyDelete
  57. QuickBooks Pro Support QuickBooks Pro has managed to get simple for a company person to produce an invoice, track expense and automatically backup data in order to avoid losing them at any cost. This particular QuickBooks Support can be installed as much as three computers and can be simultaneously accessed to efficiently retain the accounts.

    ReplyDelete
  58. Different HP Printer models have different steps for HP Printer Support Phone Number troubleshooting. Therefore, to fix any error codes, the user needs to manually clean the print head or just replace it.

    ReplyDelete
  59. This might refresh the machine and solve the issue where HP Laptop won’t turn on. The HP Inkjet Printer Support Phone Number user may also unplug the USB cable to prevent the matter. And, eventually, it will probably repair the problem of HP laptop won’t turn on even when plugged in.

    ReplyDelete
  60. Within the window “get payroll updates” you can examine whether you're making use of the latest updates or perhaps not. For every information or update, you can contact QuickBooks Payroll Support Number.

    ReplyDelete
  61. Our QuickBooks Technical Support Phone Number are terribly dedicated and might solve your entire issues without the fuss. In the event that you call, you are greeted by our client service representative when taking all of your concern he/she will transfer your preference into the involved department. The best part is the fact that not just you’ll prepare you to ultimately resolve your problems nevertheless you are often acquiesced by our technicians and he/she could well keep updating you concerning your problems. it's likely you have a whole information what the problem your package is facing.

    ReplyDelete
  62. Our specialist can surely do wonders as well as do it every single day when a person comes to us due to their QuickBooks problems. Our QuickBooks Support Number team, especially, tackle every bugs and error of QuickBooks.

    ReplyDelete
  63. QuickBooks Support users tend to be found in situations where they need to face most of the performance plus some other errors as a result of various causes inside their computer system.

    ReplyDelete
  64. QuickBooks Desktop version is frequently additionally split into QuickBooks professional, QuickBooks Premier and QuickBooks Enterprise. you’ll get the version and this can be additional apt for your needs. you must additionally get guidance and support services for the code that square measure obtainable 24/7. If just in case you come across any QuickBooks errors or problems or would like any facilitate, you’ll dial the direct line variety to achieve the QuickBooks Payroll Support.

    ReplyDelete

  65. QuickBooks Support Phone Number clients return to us several times. We keep all the data safe plus in secrecy. We are going to never share it with other people. Thus, you can count on us in terms of nearly every data.

    ReplyDelete
  66. We are widely recognized support providers for QuickBooks accounting solutions. Your QuickBooks software issues will start vanishing as soon as you receive linked to us at QuickBooks Support Phone Number. To eliminate the errors permanently, our support team establish a remote experience of your PC from which QuickBooks is installed.

    ReplyDelete
  67. Hope now you recognize that just how to interact with QuickBooks Enterprise Tech Support Phone Number. We've been independent alternative party support company for intuit QuickBooks, we don't have just about any link with direct QuickBooks, the employment of name Images and logos on website simply for reference purposes only.

    ReplyDelete
  68. If you are getting unwanted errors when working with your QuickBooks Enterprise software program and you do not know how to deal with it, our QuickBooks Enterprise Support Phone Number team are here to provide you with the best solutions in resolving the errors so that your business does not get affected and your productivity grows without having problems. Our QuickBooks Enterprise support toll-free number to get unlimited technical support. The well-trained, highly capable and experienced technical support experts can resolve your issues and give you the best solutions.

    ReplyDelete
  69. I learned World's Trending Technology from certified experts for free of cost. I Got a job in decent Top MNC Company with handsome 14 LPA salary, I have learned the World's Trending Technology from Python training in pune experts who know advanced concepts which can help to solve any type of Real-time issues in the field of Python. Really worth trying instant approval blog commenting sites

    ReplyDelete
  70. wonderful thanks for sharing an amazing idea. keep it...

    eTechno Soft Solutions offers the industry recognized Job Oriented Training in Bangalore that combines corporate training, online training, and classroom training effectively to fulfill the educational demands of the students worldwide.

    ReplyDelete
  71. Hopefully, you recognize the style well by know and learn how to take care of this error. He steps will help to fix the problem efficiently. If you would like to learn How To Resolve Quickbooks Error 9999, you can continue reading this blog.

    ReplyDelete
  72. Good article!!! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…

    python Training in chennai

    python Course in chennai

    ReplyDelete
  73. Wonderful blog. It is really informative to all.keep update more information about this
    Benefits of Using Software Testing
    Importance of Software Testing in Businesses

    ReplyDelete
  74. This post is so interactive and informative.keep update more information...
    Hadoop Training in Anna Nagar
    Big data training in chennai


    ReplyDelete
  75. This post is so helpfull and informative.Keep updating with more information...
    IELTS Exam
    IELTS Points

    ReplyDelete
  76. Thanku for sharing this information. Your post is very beneficial for us and those who searching System Malfunction Fault Code 179, In case of any doubt or technical glitch, contact our expert team of Asquare Cloud hosting at +1(855)-738-0359.

    ReplyDelete
  77. This post is so interactive and informative.keep update more information...
    AWS Training in Tambaram
    AWS Training in Chennai

    ReplyDelete
  78. how to fix your QuickBooks error code 20 This error code that displays “Printer Not Activated” or “print window hangs” is one of the common error codes reported by QuickBooks users. The error indicates that when the user upgrades from Windows XP or Vista to Windows 7, the new operating system removes the use of the HKEY_CURRENT_CONFIGSoftware key in the registry settings.need any help contact our expert thank you

    ReplyDelete