Download the PHP package nguyenanhung/30-seconds-of-php-code without Composer
On this page you can find all versions of the php package nguyenanhung/30-seconds-of-php-code. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nguyenanhung/30-seconds-of-php-code
More information about nguyenanhung/30-seconds-of-php-code
Files in nguyenanhung/30-seconds-of-php-code
Package 30-seconds-of-php-code
Short Description A curated collection of useful PHP snippets that you can understand in 30 seconds or less.
License MIT
Informations about the package 30-seconds-of-php-code
30 seconds of php code
A curated collection of useful PHP snippets that you can understand in 30 seconds or less.
Note: This project is inspired by 30 Seconds of Code, but there is no affiliation with that project.
Table of Contents
📚 Array
View contents
* [`all`](#all) * [`any`](#any) * [`chunk`](#chunk) * [`deepFlatten`](#deepflatten) * [`drop`](#drop) * [`findLast`](#findlast) * [`findLastIndex`](#findlastindex) * [`flatten`](#flatten) * [`groupBy`](#groupby) * [`hasDuplicates`](#hasduplicates) * [`head`](#head) * [`last`](#last) * [`pluck`](#pluck) * [`pull`](#pull) * [`reject`](#reject) * [`remove`](#remove) * [`tail`](#tail) * [`take`](#take) * [`without`](#without) * [`orderBy`](#orderby)➗ Math
View contents
* [`average`](#average) * [`factorial`](#factorial) * [`fibonacci`](#fibonacci) * [`gcd`](#gcd) * [`isEven`](#iseven) * [`isPrime`](#isprime) * [`lcm`](#lcm) * [`median`](#median) * [`maxN`](#maxn) * [`minN`](#minn) * [`approximatelyEqual`](#approximatelyequal) * [`clampNumber`](#clampnumber)📜 String
View contents
* [`endsWith`](#endswith) * [`firstStringBetween`](#firststringbetween) * [`isAnagram`](#isanagram) * [`isLowerCase`](#islowercase) * [`isUpperCase`](#isuppercase) * [`palindrome`](#palindrome) * [`startsWith`](#startswith) * [`countVowels`](#countvowels) * [`decapitalize`](#decapitalize) * [`isContains`](#iscontains)🎛️ Function
View contents
* [`compose`](#compose) * [`memoize`](#memoize) * [`curry`](#curry) * [`once`](#once) * [`variadicFunction`](#variadicfunction)📚 Array
all
Returns true
if the provided function returns true
for all elements of an array, false
otherwise.
Examples
⬆ Back to top
any
Returns true
if the provided function returns true
for at least one element of an array, false
otherwise.
Examples
⬆ Back to top
chunk
Chunks an array into smaller arrays of a specified size.
Examples
⬆ Back to top
deepFlatten
Deep flattens an array.
Examples
⬆ Back to top
drop
Returns a new array with n
elements removed from the left.
Examples
⬆ Back to top
findLast
Returns the last element for which the provided function returns a truthy value.
Examples
⬆ Back to top
findLastIndex
Returns the index of the last element for which the provided function returns a truthy value.
Examples
⬆ Back to top
flatten
Flattens an array up to the one level depth.
Examples
⬆ Back to top
groupBy
Groups the elements of an array based on the given function.
Examples
⬆ Back to top
hasDuplicates
Checks a flat list for duplicate values. Returns true
if duplicate values exists and false
if values are all unique.
Examples
⬆ Back to top
head
Returns the head of a list.
Examples
⬆ Back to top
last
Returns the last element in an array.
Examples
⬆ Back to top
pluck
Retrieves all of the values for a given key:
Examples
⬆ Back to top
pull
Mutates the original array to filter out the values specified.
Examples
⬆ Back to top
reject
Filters the collection using the given callback.
Examples
⬆ Back to top
remove
Removes elements from an array for which the given function returns false.
Examples
⬆ Back to top
tail
Returns all elements in an array except for the first one.
Examples
⬆ Back to top
take
Returns an array with n elements removed from the beginning.
Examples
⬆ Back to top
without
Filters out the elements of an array, that have one of the specified values.
Examples
⬆ Back to top
orderBy
Sorts a collection of arrays or objects by key.
Examples
⬆ Back to top
➗ Math
average
Returns the average of two or more numbers.
Examples
⬆ Back to top
factorial
Calculates the factorial of a number.
Examples
⬆ Back to top
fibonacci
Generates an array, containing the Fibonacci sequence, up until the nth term.
Examples
⬆ Back to top
gcd
Calculates the greatest common divisor between two or more numbers.
Examples
⬆ Back to top
isEven
Returns true
if the given number is even, false
otherwise.
Examples
⬆ Back to top
isPrime
Checks if the provided integer is a prime number.
Examples
⬆ Back to top
lcm
Returns the least common multiple of two or more numbers.
Examples
⬆ Back to top
median
Returns the median of an array of numbers.
Examples
⬆ Back to top
maxN
Returns the n maximum elements from the provided array.
Examples
⬆ Back to top
minN
Returns the n minimum elements from the provided array.
Examples
⬆ Back to top
approximatelyEqual
Checks if two numbers are approximately equal to each other.
Use abs() to compare the absolute difference of the two values to epsilon. Omit the third parameter, epsilon, to use a default value of 0.001.
Examples
⬆ Back to top
clampNumber
Clamps num within the inclusive range specified by the boundary values a and b.
If num falls within the range, return num. Otherwise, return the nearest number in the range.
Examples
⬆ Back to top
📜 String
endsWith
Check if a string is ends with a given substring.
Examples
⬆ Back to top
firstStringBetween
Returns the first string there is between the strings from the parameter start and end.
Examples
⬆ Back to top
isAnagram
Compare two strings and returns true
if both strings are anagram, false
otherwise.
Examples
⬆ Back to top
isLowerCase
Returns true
if the given string is lower case, false
otherwise.
Examples
⬆ Back to top
isUpperCase
Returns true
if the given string is upper case, false otherwise.
Examples
⬆ Back to top
palindrome
Returns true
if the given string is a palindrome, false
otherwise.
Examples
⬆ Back to top
startsWith
Check if a string starts with a given substring.
Examples
⬆ Back to top
countVowels
Returns number of vowels in provided string.
Use a regular expression to count the number of vowels (A, E, I, O, U) in a string.
Examples
⬆ Back to top
decapitalize
Decapitalizes the first letter of a string.
Decapitalizes the first letter of the string and then adds it with rest of the string. Omit the parameter to keep the rest of the string intact, or set it to to convert to uppercase.
Examples
⬆ Back to top
isContains
Check if a word / substring exist in a given string input.
Using strpos
to find the position of the first occurrence of a substring in a string. Returns either true
or false
Examples
⬆ Back to top
🎛️ Function
compose
Return a new function that composes multiple functions into a single callable.
Examples
⬆ Back to top
memoize
Memoization of a function results in memory.
Examples
⬆ Back to top
curry
Curries a function to take arguments in multiple calls.
Examples
⬆ Back to top
once
Call a function only once.
Examples
⬆ Back to top
variadicFunction
Variadic functions allows you to capture a variable number of arguments to a function.
The function accepts any number of variables to execute the code. It uses a for loop to iterate over the parameters.
Examples
⬆ Back to top
Contribute
You're always welcome to contribute to this project. Please read the contribution guide.
License
This project is licensed under the MIT License - see the License File for details
All versions of 30-seconds-of-php-code with dependencies
symfony/filesystem Version 3.4.17
jbzoo/data Version 1.6.0
jbzoo/utils Version 1.7.11
mobiledetect/mobiledetectlib Version ^2.8
zendframework/zend-escaper Version ^2.6
theseer/directoryscanner Version 1.3.2
nesbot/carbon Version 1.36.1