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 run an artisan command from a controller

How to round a number in JS?

How to Enable Directory Listings in Apache with .htaccess

How to generate an array for a dropdown (with ['key' => 'value']) suitable for a dropdown, from a Laravel collection of Eloquent objects?

How to check if a relation was loaded on an Eloquent model already?

How to prevent Eloquent from adding created_at or updated_at timestamps?

How to split a string into an array, in JS

How to block an IP address in .htaccess

An overview of every main PHP array function

What is the difference between integration and unit tests?