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

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.


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 generate an array for a dropdown (with ['key' => 'value']) suitable for a dropdown, from a Laravel collection of Eloquent objects?

What are Apache MPMs?

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

How to Enable Directory Listings in Apache with .htaccess

How can you check if a variable is alphanum (alphanumeric, letters and numbers only) in PHP?

How to exclude URLs from the Laravel CSRF protection?

How to use Anonymous classes in PHP 7?

Push vs Pop vs Shift vs Unshift

A list of operators on Eloquent's where() method

What is WordPress default Apache .htaccess rules?