PHP Code Snippets

String to Keyed Array

This function is an ideal way to take a string and have separators to parse keys and values. This is great for giving a definitions list or just have the ability to have an array from long strings.

Default separators are == and &&, although you may define your own by sending the strings to separate by

Output:

Fizz Buzz Programming Test

The FizzBuzz Programming Script is a test for candidates to demonstrate their coding concepts. Many employers will ask for a specified numbered loop (usually 100) and have it print the word FizzBuzz on the combined defined numbers (usually 3 & 5), Fizz on a defined number (usually 3) and Buzz on another defined number (usually 5). This script is designed to allow you to declare the numbers required for the FizzBuzz test. You may also define true or false to display the numbers before and after the Fizz and Buzz.

Default numbers are Fizz on 3, Buzz on 5, Loop 100 times and do not display the numbers before and after the Fizz and Buzz.

Output (first example only):

1
2
buzz
4
5
buzz
7
8
fizz
10
11
buzz
13
14
buzz
16
17
fizz
19
20
buzz
22
23
buzz
25
26
fizz
28
29
buzz
31
32
buzz
34
35
fizz
37
38
buzz
40
41
buzz
43
44
fizz
46
47
buzz
49
50

Decimal to Fraction

This function will convert a decimal to a fraction with a denominator up to 128 (example 13/128). This function uses simple PHP math functions.

A number is required.

Output:

Clean Number

This function will remove all characters except, 0 – 9, a comma and a decimal.

A string is required.

Output: