Skip to content

Added PHP language folder and created bubbleSort.php #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions PHP/bubbleSort.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

function bubble_sort($arr) {
$len = count($arr)-1;
for ($i=0; $i<$len; $i++) {
for ($j=0; $j<$len-$i; $j++) {
$k = $j+1;
if ($arr[$k] < $arr[$j]) {
// Swap elements at indices: $j, $k
list($arr[$j], $arr[$k]) = array($arr[$k], $arr[$j]);
}
}
}
return $arr;
}

$arr = array(64,34,25,12,22,11,90);

print("<pre>Before sorting\n");
print_r($arr);
print("After sorting by using bubble sort\n");
print_r(bubble_sort($arr));

?>
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Sorting algorithms implemented in different languages (for hacktoberfest). This
| Java | [`Bead Sort`](Java/BeadSort.java) [`Bogo Sort`](Java/BogoSort.java) [`Bubble Sort`](Java/BubbleSort.java) <br> [`Counting Sort`](Java/Counting%20Sort.java) [`Heap Sort`](Java/HeapSort.java) [`Insertion Sort`](Java/InsertionSort.java) <br> [`Merge Sort`](Java/MergeSort.java) [`Quick Sort`](Java/QuickSort.java) [`Radix Sort`](Java/RadixSort.java) <br> [`Selection Sort`](Java/SelectionSort.java) [`Shell Sort`](Java/ShellSort.java) [`Tim Sort`](Java/TimSort.java) <br> [`Comb Sort`](Java/CombSort.java) [`Binary Insertion Sort`](Java/BinaryInsertionSort.java) [`Gnome Sort`](Java/GnomeSort.java) [`Topological Sort`](Java/TopologicalSort.java)|
| Javascript | [`Bogo Sort`](Javascript/bogoSort.js) [`Counting Sort`](Javascript/countingSort.js) [`Heap Sort`](Javascript/HeapSort.js) [`Insertion Sort`](Javascript/Insertionsort.js) [`Merge Sort`](Javascript/MergeSort.js) <br> [`Quick Sort`](Javascript/Quicksort.js) [`Bubble Sort`](Javascript/bubbleSort.js) [`Shell Sort`](Javascript/shellSort.js ) [`Selection Sort`](Javascript/selectionSort.js) <br> [`Radix Sort`](Javascript/RadixSort.js) |
| Lua | [`Quick Sort`](Lua/quicksort.lua) |
| PHP | [`Bubble Sort`](PHP/bubbleSort.php) |
| Python | [`Bogo Sort`](Python/BogoSort.py) [`Bubble Sort`](Python/BubbleSort.py) [`Bucket Sort`](Python/BucketSort.py) [`Bubble Sort Recursive`](Python/BubbleSortRecursive.py) <br> [`Gnome Sort`](Python/GnomeSort.py) [`Insertion Sort`](Python/InsertionSort.py) [`Merge Sort`](Python/MergeSort.py) <br> [`Quick Sort`](Python/QuickSort.py) [`Radix Sort`](Python/RadixSort.py) [`Selection Sort`](Python/SelectionSort.py) <br> [`Binary Insertion Sort`](Python/BinaryInsertionSort.py) [`Heap Sort`](Python/heapSort.py) |
| Ruby | [`Bubble Sort`](Ruby/bubble_sort.rb) [`Gnome Sort`](Ruby/gnome_sort.rb) [`Quick sort`](Ruby/quick_sort.rb) [`Selection sort`](Ruby/selection_sort.rb) [`Sort`](Ruby/sort.rb) [`Reverse sort`](Ruby/reverse.rb)
| Rust | [`Bubble Sort`](Rust/Bubble_Sort.rs)
Expand Down