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 review blog posts (written by other users) before they get published on your WordPress blog?

Set PHP config Variables (like ini_set) with .htaccess

How to hide certain file types from directory listings

How to query mysql using PDO in PHP?

How to make multiple routes share the same URL structure or URL parameters

How to destroy or remove a cookie in PHP

How to check if two strings are anagrams in PHP?

What are route patterns in Laravel?

How to hide directory listing in .htaccess?

How to replace whitespace with a single space