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 get the type of a variable in JS?

How to use subdomains as parameters in your routes (or in your web.php file)

How to find the index of a value in an array in JS?

Point all requests to one PHP file

How to add and remove items to an array in JS?

What is Agile software development?

How to create random numbers in JS?

How to block an IP range based on CIDR in Apache with .htaccess

How to set the Expires header in .htaccess

How to hide certain file types from directory listings