PHP String Functions
--------------------
1. strlen($str) - Returns the length of a string
Example: strlen("Hello") => 5
2. strtoupper($str) - Converts string to uppercase
Example: strtoupper("php") => "PHP"
3. strtolower($str) - Converts string to lowercase
Example: strtolower("PHP") => "php"
4. substr($str, $start, $length) - Returns part of a string
Example: substr("Hello", 1, 3) => "ell"
5. strpos($haystack, $needle) - Finds first occurrence
Example: strpos("Hello", "e") => 1
6. strrpos($haystack, $needle) - Finds last occurrence
Example: strrpos("Hello Hello", "l") => 9
7. str_replace($search, $replace, $subject) - Replace all occurrences
Example: str_replace("world", "PHP", "Hello world") => "Hello PHP"
8. str_ireplace($search, $replace, $subject) - Case-insensitive replace
Example: str_ireplace("WORLD", "PHP", "Hello world") => "Hello PHP"
9. explode($delimiter, $string) - Splits string into array
Example: explode(",", "a,b,c") => ["a","b","c"]
10. implode($glue, $pieces) - Joins array into string
Example: implode("-", ["a","b","c"]) => "a-b-c"
11. trim($str) - Removes whitespace
Example: trim(" Hello ") => "Hello"
12. str_repeat($str, $times) - Repeats string
Example: str_repeat("abc", 3) => "abcabcabc"
13. strrev($str) - Reverses string
Example: strrev("Hello") => "olleH"
14. ucfirst($str) - Capitalizes first letter
Example: ucfirst("hello") => "Hello"
15. ucwords($str) - Capitalizes each word
Example: ucwords("hello world") => "Hello World"
16. htmlspecialchars($str) - Converts special characters
Example: htmlspecialchars("<b>") => "<b>"
17. number_format($num) - Formats number with commas
Example: number_format(1234567) => "1,234,567"
PHP Array Functions
-------------------
1. count($array) - Number of elements
Example: count([1,2,3]) => 3
2. array_push($array, $val) - Add to end
Example: array_push([1,2,3], 4) => [1,2,3,4]
3. array_pop($array) - Remove last
Example: array_pop([1,2,3]) => 3
4. array_shift($array) - Remove first
Example: array_shift([1,2,3]) => 1
5. array_unshift($array, $val) - Add to beginning
Example: array_unshift([1,2,3], 0) => [0,1,2,3]
6. array_merge($a, $b) - Merge arrays
Example: array_merge([1], [2,3]) => [1,2,3]
7. array_diff($a, $b) - Difference
Example: array_diff([1,2,3], [2]) => [1,3]
8. array_intersect($a, $b) - Common elements
Example: array_intersect([1,2], [2,3]) => [2]
9. array_keys($array) - Get keys
Example: array_keys(["a"=>1,"b"=>2]) => ["a", "b"]
10. array_values($array) - Get values
Example: array_values(["a"=>1,"b"=>2]) => [1, 2]
11. array_key_exists($key, $array) - Check key
Example: array_key_exists("a", ["a"=>1]) => true
12. in_array($val, $array) - Check value
Example: in_array(2, [1,2,3]) => true
13. array_slice($array, $offset, $length) - Slice array
Example: array_slice([1,2,3,4], 1, 2) => [2,3]
14. array_splice($array, $offset, $length) - Remove/replace
Example: array_splice([1,2,3,4], 1, 2) => [2,3]
15. array_unique($array) - Remove duplicates
Example: array_unique([1,2,2,3]) => [1,2,3]
16. array_reverse($array) - Reverse array
Example: array_reverse([1,2,3]) => [3,2,1]
17. array_map($callback, $array) - Apply function
Example: array_map('strtoupper', ['a','b']) => ['A','B']
18. array_filter($array) - Filter elements
Example: array_filter([0,1,2]) => [1,2]
19. array_reduce($array, $callback) - Reduce to single value
Example: array_reduce([1,2,3], fn($c,$i)=>$c+$i) => 6