diff --git a/archive/p/php/README.md b/archive/p/php/README.md index ec51b1299..9f98f9347 100644 --- a/archive/p/php/README.md +++ b/archive/p/php/README.md @@ -16,6 +16,7 @@ Welcome to Sample Programs in PHP! - [Palindrome Word in PHP][11] - [ROT13 in PHP][15] - [String Reverse in PHP][10] +- [Insertion Sort in PHP][17] ## Fun Facts @@ -47,3 +48,4 @@ Welcome to Sample Programs in PHP! [14]: https://www.w3resource.com/php-exercises/searching-and-sorting-algorithm/searching-and-sorting-algorithm-exercise-17.php [15]: https://github.com/TheRenegadeCoder/sample-programs/issues/1530 [16]: https://github.com/TheRenegadeCoder/sample-programs/issues/1533 +[17]: https://github.com/TheRenegadeCoder/sample-programs/issues/1524 diff --git a/archive/p/php/insertion-sort.php b/archive/p/php/insertion-sort.php new file mode 100644 index 000000000..8da021593 --- /dev/null +++ b/archive/p/php/insertion-sort.php @@ -0,0 +1,21 @@ +=0 && $my_array[$j] > $val){ + $my_array[$j+1] = $my_array[$j]; + $j--; + } + $my_array[$j+1] = $val; + } +return $my_array; +} +$test_array = array(3, 0, 2, 5, -1, 4, 1); +echo "Original Array :\n"; +echo implode(', ',$test_array ); +echo "\nSorted Array :\n"; +print_r(insertion_Sort($test_array)); +?>