Related Content
Generating Colour Palettes From Images In PHP
A common web design pattern is to incorporate an image into the design of the page. This creates a tighter integration with the image and the rest of the page.
The main issue in designing a page around the image is that the colours of the page must match the image. Otherwise this creates a dissonance between the image and the styles of the site.
Validating XML Files With XML Schema Definitions In PHP
XML is a useful format for configuration, data storage, and transmitting data from one system to another. As a human readable format that can be easily read by machines it quickly gained favor in lots of different systems as a mechanism for data storage.
Creating A Character Bitmap In PHP
I was watching a video from NDC by Dylan Beattie the other day on The Story of Typography and a particular section stood out to me.
Approximating Pi Using A Circle And A Square
Pi day was a few weeks ago, but I came across this simple approximation of pi recently and decided to put together an example in PHP since it seemed pretty simple.
This approximation of pi centers around a real world example, but we can simulate this using some code.
Drawing A Parabolic Curve With Straight Lines In PHP
A parabolic curve is a type of curve where every point is an equal distance from a focal point. There a number of different way to generate this sort of curve using math, but one of the simplest is to use straight lines to create the illusion of the curve.
Recreating Spotify Wrapped In PHP
I quite like the end of the year report from Spotify that they call "Wrapped". This is a little application in which they tell you what your favorite artist was and what sort of genres you listened to the most during the year.
Comments
Why do you count right as count($array) - 1. Why do you need this -1 ?
Submitted by Valeriy on Mon, 03/30/2020 - 12:27
PermalinkThis is because the count() function will return the length of the array, but if we want to get the last item in the array using this value it will be 1 item beyond the end of the array.
The array I'm creating here starts from 0 so although the length is 10, the index of the last item is 9.
Submitted by giHlZp8M8D on Tue, 03/31/2020 - 15:17
PermalinkA good binary search implementation does not return NULL if element is not found. It should return the correct insertion index for the element instead. This way it can serve both purposes (retrieval and insertion), because it only costs O(1) to check if the element at the returned index is the needle.
Submitted by BASTA! on Sun, 06/20/2021 - 21:03
PermalinkThat's actually a really good point. I initially though "how would you know if the value was not found versus a found index", but you are right in that you would only need to go and check the index for the return value. I might have another go at this.
Thank you for the comment!
Submitted by giHlZp8M8D on Mon, 06/21/2021 - 08:37
PermalinkAdd new comment