What is Bubble sort, and how to write an implementation of it in PHP

General Webdev and Programming Stuff: What is Bubble sort, and how to write an implementation of it in PHP

Bubble sort (aka 'sinking sort') is a basic sorting algorithm. It cycles through all items in the list, comparing one to the next item. If the next item is smaller than the current item it is looking at, their values get swapped. If any swap was made, the cycle starts again and until it goes through all items without doing any swaps.

I do not recommend that you ever code a bubble sort algo in PHP! Use the built in PHP functions, they will be much faster than (almost) anything coded in PHP. The core functions such as sort() (which uses an implementation of Quicksort) are coded in C, and are much faster than what you can do in PHP. This is just for educational reasons.

webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about What is Bubble sort, and how to write an implementation of it in PHP

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the General Webdev and Programming Stuff language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to find the 2nd most common item in an array?

How to force gzip compression in Apache with .htaccess

What are the main error types in PHP

How to find the intersection (same values) from two arrays?

How to select what columns to return when calling ::all()

How do you run a PHP script from the command line?

How to check if a (blade) view file exists

How to make Apache force download of files (in .htaccess)

How to set up an alias to map one directory to another destination

How to show (or log) all SQL queries executed by Laravel