PHP code example of baka / support
1. Go to this page and download the library: Download baka/support library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
baka / support example snippets
all([2, 3, 4, 5], function ($item) {
return $item > 1;
}); // true
any([1, 2, 3, 4], function ($item) {
return $item < 2;
}); // true
deepFlatten([1, [2], [[3], 4], 5]); // [1, 2, 3, 4, 5]
drop([1, 2, 3]); // [2,3]
drop([1, 2, 3], 2); // [3]
findLast([1, 2, 3, 4], function ($n) {
return ($n % 2) === 1;
});
// 3
findLastIndex([1, 2, 3, 4], function ($n) {
return ($n % 2) === 1;
});
// 2
flatten([1, [2], 3, 4]); // [1, 2, 3, 4]
groupBy(['one', 'two', 'three'], 'strlen'); // [3 => ['one', 'two'], 5 => ['three']]
hasDuplicates([1, 2, 3, 4, 5, 5]); // true
head([1, 2, 3]); // 1
last([1, 2, 3]); // 3
pluck([
['product_id' => 'prod-100', 'name' => 'Desk'],
['product_id' => 'prod-200', 'name' => 'Chair'],
], 'name');
// ['Desk', 'Chair']
$items = ['a', 'b', 'c', 'a', 'b', 'c'];
pull($items, 'a', 'c'); // $items will be ['b', 'b']
reject(['Apple', 'Pear', 'Kiwi', 'Banana'], function ($item) {
return strlen($item) > 4;
}); // ['Pear', 'Kiwi']
remove([1, 2, 3, 4], function ($n) {
return ($n % 2) === 0;
});
// [0 => 1, 2 => 3]
tail([1, 2, 3]); // [2, 3]
take([1, 2, 3], 5); // [1, 2, 3]
take([1, 2, 3, 4, 5], 2); // [1, 2]
without([2, 1, 2, 3], 1, 2); // [3]
orderBy(
[
['id' => 2, 'name' => 'Joy'],
['id' => 3, 'name' => 'Khaja'],
['id' => 1, 'name' => 'Raja']
],
'id',
'desc'
); // [['id' => 3, 'name' => 'Khaja'], ['id' => 2, 'name' => 'Joy'], ['id' => 1, 'name' => 'Raja']]
endsWith('Hi, this is me', 'me'); // true
firstStringBetween('This is a [custom] string', '[', ']'); // custom
isAnagram('act', 'cat'); // true
isLowerCase('Morning shows the day!'); // false
isLowerCase('hello'); // true
isUpperCase('MORNING SHOWS THE DAY!'); // true
isUpperCase('qUick Fox'); // false
palindrome('racecar'); // true
palindrome(2221222); // true
startsWith('Hi, this is me', 'Hi'); // true
countVowels('sampleInput'); // 4
decapitalize('FooBar'); // 'fooBar'
contains('This is an example string', 'example'); // true
contains('This is an example string', 'hello'); // false