PHP code example of lodash-php / lodash-php

1. Go to this page and download the library: Download lodash-php/lodash-php 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/ */

    

lodash-php / lodash-php example snippets




use function _\each;

each([1, 2, 3], function (int $item) {
    var_dump($item);
});



_::each([1, 2, 3], function (int $item) {
    var_dump($item);
});


 use function _\chunk;

chunk(['a', 'b', 'c', 'd'], 2)
// => [['a', 'b'], ['c', 'd']]

chunk(['a', 'b', 'c', 'd'], 3)
// => [['a', 'b', 'c'], ['d']]



 use function _\compact;

compact([0, 1, false, 2, '', 3])
// => [1, 2, 3]



 use function _\concat;

$array = [1];
$other = concat($array, 2, [3], [[4]]);

var_dump($other)
// => [1, 2, 3, [4]]

var_dump($array)
// => [1]



 use function _\difference;

difference([2, 1], [2, 3])
// => [1]



 use function _\differenceBy;

differenceBy([2.1, 1.2], [2.3, 3.4], 'floor')
// => [1.2]



 use function _\differenceWith;

$objects = [[ 'x' => 1, 'y' => 2 ], [ 'x' => 2, 'y' => 1 ]]

differenceWith($objects, [[ 'x' => 1, 'y' => 2 ]], '_::isEqual')
// => [[ 'x' => 2, 'y' => 1 ]]



 use function _\drop;

drop([1, 2, 3])
// => [2, 3]

drop([1, 2, 3], 2)
// => [3]

drop([1, 2, 3], 5)
// => []

drop([1, 2, 3], 0)
// => [1, 2, 3]



 use function _\dropRight;

dropRight([1, 2, 3])
// => [1, 2]

dropRight([1, 2, 3], 2)
// => [1]

dropRight([1, 2, 3], 5)
// => []

dropRight([1, 2, 3], 0)
// => [1, 2, 3]



 use function _\dropRightWhile;

$users = [
[ 'user' => 'barney',  'active' => false ],
[ 'user' => 'fred',    'active' => true ],
[ 'user' => 'pebbles', 'active' => true ]
]

dropRightWhile($users, function($user) { return $user['active']; })
// => objects for ['barney']



 use function _\dropWhile;

$users = [
[ 'user' => 'barney',  'active' => true ],
[ 'user' => 'fred',    'active' => true ],
[ 'user' => 'pebbles', 'active' => false ]
]

dropWhile($users, function($user) { return $user['active']; } )
// => objects for ['pebbles']



 use function _\every;

every([true, 1, null, 'yes'], function ($value) { return is_bool($value);})
// => false

$users = [
['user' => 'barney', 'age' => 36, 'active' => false],
['user' => 'fred', 'age' => 40, 'active' => false],
];

// The `matches` iteratee shorthand.
$this->assertFalse(every($users, ['user' => 'barney', 'active' => false]));
// false

// The `matchesProperty` iteratee shorthand.
$this->assertTrue(every($users, ['active', false]));
// true

// The `property` iteratee shorthand.
$this->assertFalse(every($users, 'active'));
//false




 use function _\findIndex;

$users = [
['user' => 'barney',  'active' => false],
['user' => 'fred',    'active' => false],
['user' => 'pebbles', 'active' => true],
];

findIndex($users, function($o) { return $o['user'] s== 'barney'; });
// => 0

// The `matches` iteratee shorthand.
findIndex($users, ['user' => 'fred', 'active' => false]);
// => 1

// The `matchesProperty` iteratee shorthand.
findIndex($users, ['active', false]);
// => 0

// The `property` iteratee shorthand.
findIndex($users, 'active');
// => 2



 use function _\findLastIndex;

$users = [
['user' => 'barney',  'active' => true ],
['user' => 'fred',    'active' => false ],
['user' => 'pebbles', 'active' => false ]
]

findLastIndex($users, function($user) { return $user['user'] === 'pebbles'; })
// => 2



 use function _\flatten;

flatten([1, [2, [3, [4]], 5]])
// => [1, 2, [3, [4]], 5]



 use function _\flattenDeep;

flattenDeep([1, [2, [3, [4]], 5]]);
// => [1, 2, 3, 4, 5]



 use function _\flattenDepth;

$array = [1, [2, [3, [4]], 5]]

flattenDepth($array, 1)
// => [1, 2, [3, [4]], 5]

flattenDepth($array, 2)
// => [1, 2, 3, [4], 5]



 use function _\fromPairs;

fromPairs([['a', 1], ['b', 2]])
// => stdClass(
// 'a' => 1,
//'b' => 2,
// )



 use function _\head;

head([1, 2, 3])
// => 1

head([])
// => null



 use function _\indexOf;

indexOf([1, 2, 1, 2], 2)
// => 1

// Search from the `fromIndex`.
indexOf([1, 2, 1, 2], 2, 2)
// => 3



 use function _\initial;

initial([1, 2, 3])
// => [1, 2]



 use function _\intersection;

intersection([2, 1], [2, 3])
// => [2]



 use function _\intersectionBy;

intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor)
// => [2.1]

// The `property` iteratee shorthand.
intersectionBy([[ 'x' => 1 ]], [[ 'x' => 2 ], [ 'x' => 1 ]], 'x');
// => [[ 'x' => 1 ]]



 use function _\intersectionWith;

$objects = [[ 'x' => 1, 'y' => 2 ], [ 'x' => 2, 'y' => 1 ]]
$others = [[ 'x' => 1, 'y' => 1 ], [ 'x' => 1, 'y' => 2 ]]

intersectionWith($objects, $others, '_::isEqual')
// => [[ 'x' => 1, 'y' => 2 ]]



 use function _\last;

last([1, 2, 3])
// => 3



 use function _\lastIndexOf;

lastIndexOf([1, 2, 1, 2], 2)
// => 3

// Search from the `fromIndex`.
lastIndexOf([1, 2, 1, 2], 2, 2)
// => 1



 use function _\nth;

$array = ['a', 'b', 'c', 'd']

nth($array, 1)
// => 'b'

nth($array, -2)
// => 'c'



 use function _\pull;

$array = ['a', 'b', 'c', 'a', 'b', 'c']

pull($array, 'a', 'c')
var_dump($array)
// => ['b', 'b']



 use function _\pullAll;

$array = ['a', 'b', 'c', 'a', 'b', 'c']

pullAll($array, ['a', 'c'])
var_dump($array)
// => ['b', 'b']



 use function _\pullAllBy;

$array = [[ 'x' => 1 ], [ 'x' => 2 ], [ 'x' => 3 ], [ 'x' => 1 ]]

pullAllBy($array, [[ 'x' => 1 ], [ 'x' => 3 ]], 'x')
var_dump($array)
// => [[ 'x' => 2 ]]



 use function _\pullAllWith;

$array = [[ 'x' => 1, 'y' => 2 ], [ 'x' => 3, 'y' => 4 ], [ 'x' => 5, 'y' => 6 ]]

pullAllWith($array, [[ 'x' => 3, 'y' => 4 ]], '_\isEqual')
var_dump($array)
// => [[ 'x' => 1, 'y' => 2 ], [ 'x' => 5, 'y' => 6 ]]



 use function _\pullAt;

$array = ['a', 'b', 'c', 'd']
$pulled = pullAt($array, [1, 3])

var_dump($array)
// => ['a', 'c']

var_dump($pulled)
// => ['b', 'd']



 use function _\remove;

$array = [1, 2, 3, 4]
$evens = remove($array, function ($n) { return $n % 2 === 0; })

var_dump($array)
// => [1, 3]

var_dump($evens)
// => [2, 4]



 use function _\sample;

sample([1, 2, 3, 4])
// => 2



 use function _\sampleSize;

sampleSize([1, 2, 3], 2)
// => [3, 1]

sampleSize([1, 2, 3], 4)
// => [2, 3, 1]



 use function _\shuffle;

shuffle([1, 2, 3, 4])
// => [4, 1, 3, 2]



 use function _\tail;

tail([1, 2, 3])
// => [2, 3]



 use function _\take;

take([1, 2, 3])
// => [1]

take([1, 2, 3], 2)
// => [1, 2]

take([1, 2, 3], 5)
// => [1, 2, 3]

take([1, 2, 3], 0)
// => []



 use function _\takeRight;

takeRight([1, 2, 3])
// => [3]

takeRight([1, 2, 3], 2)
// => [2, 3]

takeRight([1, 2, 3], 5)
// => [1, 2, 3]

takeRight([1, 2, 3], 0)
// => []



 use function _\takeRightWhile;

$users = [
[ 'user' => 'barney',  'active' => false ],
[ 'user' => 'fred',    'active' => true ],
[ 'user' => 'pebbles', 'active' => true ]
];

takeRightWhile($users, function($value) { return $value['active']; })
// => objects for ['fred', 'pebbles']



 use function _\takeWhile;

$users = [
[ 'user' => 'barney',  'active' => true ],
[ 'user' => 'fred',    'active' => true ],
[ 'user' => 'pebbles', 'active' => false ]
]

takeWhile($users, function($value) { return $value['active']; })
// => objects for ['barney', 'fred']



 use function _\union;

union([2], [1, 2])
// => [2, 1]



 use function _\unionBy;

unionBy([2.1], [1.2, 2.3], 'floor')
// => [2.1, 1.2]

// The `_::property` iteratee shorthand.
unionBy([['x' => 1]], [['x' => 2], ['x' => 1]], 'x');
// => [['x' => 1], ['x' => 2]]



 use function _\unionWith;

$objects = [['x' => 1, 'y' => 2], ['x' => 2, 'y' => 1]]
$others = [['x' => 1, 'y' => 1], ['x' => 1, 'y' => 2]]

unionWith($objects, $others, '_::isEqual')
// => [['x' => 1, 'y' => 2], ['x' => 2, 'y' => 1], ['x' => 1, 'y' => 1]]



 use function _\uniq;

uniq([2, 1, 2])
// => [2, 1]s



 use function _\uniqBy;

uniqBy([2.1, 1.2, 2.3], 'floor')
// => [2.1, 1.2]



 use function _\uniqWith;

$objects = [['x' => 1, 'y' => 2], ['x' => 2, 'y' => 1], ['x' => 1, 'y' => 2]]

uniqWith($objects, '_::isEqual')
// => [['x' => 1, 'y' => 2], ['x' => 2, 'y' => 1]]



 use function _\unzip;

$zipped = zip(['a', 'b'], [1, 2], [true, false])
// => [['a', 1, true], ['b', 2, false]]

unzip($zipped)
// => [['a', 'b'], [1, 2], [true, false]]



 use function _\unzipWith;

$zipped = zip([1, 2], [10, 20], [100, 200])
// => [[1, 10, 100], [2, 20, 200]]

unzipWith(zipped, '_::add')
// => [3, 30, 300]



 use function _\without;

without([2, 1, 2, 3], 1, 2)
// => [3]



 use function _\zip;

zip(['a', 'b'], [1, 2], [true, false])
// => [['a', 1, true], ['b', 2, false]]



 use function _\zipObject;

zipObject(['a', 'b'], [1, 2])
/* => object(stdClass)#210 (2) {
["a"] => int(1)
["b"] => int(2)
}
*\/



 use function _\zipObjectDeep;

zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2])
/* => class stdClass#20 (1) {
public $a => class stdClass#19 (1) {
public $b =>
array(2) {
[0] => class stdClass#17 (1) {
public $c => int(1)
}
[1] => class stdClass#18 (1) {
public $d => int(2)
}
}
}
}
*\/



 use function _\zipWith;

zipWith([1, 2], [10, 20], [100, 200], function($a, $b, $c) { return $a + $b + $c; })
// => [111, 222]



 use function _\countBy;

countBy([6.1, 4.2, 6.3], 'floor');
// => ['6' => 2, '4' => 1]

// The `property` iteratee shorthand.
countBy(['one', 'two', 'three'], 'strlen');
// => ['3' => 2, '5' => 1]



 use function _\each;

each([1, 2], function ($value) { echo $value; })
// => Echoes `1` then `2`.

each((object) ['a' => 1, 'b' => 2], function ($value, $key) { echo $key; });
// => Echoes 'a' then 'b' (iteration order is not guaranteed).



 use function _\eachRight;

eachRight([1, 2], function($value) { echo $value; })
// => Echoes `2` then `1`.



 use function _\filter;

$users = [
[ 'user' => 'barney', 'age' => 36, 'active' => true],
[ 'user' => 'fred',   'age' => 40, 'active' => false]
];

filter($users, function($o) { return !$o['active']; });
// => objects for ['fred']

// The `matches` iteratee shorthand.
filter($users, ['age' => 36, 'active' => true]);
// => objects for ['barney']

// The `matchesProperty` iteratee shorthand.
filter($users, ['active', false]);
// => objects for ['fred']

// The `property` iteratee shorthand.
filter($users, 'active');
// => objects for ['barney']



 use function _\find;

$users = [
['user' => 'barney',  'age' => 36, 'active' => true],
['user' => 'fred',    'age' => 40, 'active' => false],
['user' => 'pebbles', 'age' => 1,  'active' => true]
];

find($users, function($o) { return $o['age'] < 40; });
// => object for 'barney'

// The `matches` iteratee shorthand.
find($users, ['age' => 1, 'active' => true]);
// => object for 'pebbles'

// The `matchesProperty` iteratee shorthand.
find($users, ['active', false]);
// => object for 'fred'

// The `property` iteratee shorthand.
find($users, 'active');
// => object for 'barney'



 use function _\findLast;

findLast([1, 2, 3, 4], function ($n) { return $n % 2 == 1; })
// => 3



 use function _\flatMap;

function duplicate($n) {
return [$n, $n]
}

flatMap([1, 2], 'duplicate')
// => [1, 1, 2, 2]



 use function _\flatMapDeep;

function duplicate($n) {
return [[[$n, $n]]];
}

flatMapDeep([1, 2], 'duplicate');
// => [1, 1, 2, 2]



 use function _\flatMapDepth;

function duplicate($n) {
return [[[$n, $n]]]
}

flatMapDepth([1, 2], 'duplicate', 2)
// => [[1, 1], [2, 2]]



 use function _\groupBy;

groupBy([6.1, 4.2, 6.3], 'floor');
// => ['6' => [6.1, 6.3], '4' => [4.2]]

groupBy(['one', 'two', 'three'], 'strlen');
// => ['3' => ['one', 'two'], '5' => ['three']]



 use function _\invokeMap;

invokeMap([[5, 1, 7], [3, 2, 1]], function($result) { sort($result); return $result;})
// => [[1, 5, 7], [1, 2, 3]]

invokeMap([123, 456], 'str_split')
// => [['1', '2', '3'], ['4', '5', '6']]



 use function _\keyBy;

$array = [
['direction' => 'left', 'code' => 97],
['direction' => 'right', 'code' => 100],
];

keyBy($array, function ($o) { return \chr($o['code']); })
// => ['a' => ['direction' => 'left', 'code' => 97], 'd' => ['direction' => 'right', 'code' => 100]]

keyBy($array, 'direction');
// => ['left' => ['direction' => 'left', 'code' => 97], 'right' => ['direction' => 'right', 'code' => 100]]



 use function _\map;

function square(int $n) {
return $n * $n;
}

map([4, 8], $square);
// => [16, 64]

map((object) ['a' => 4, 'b' => 8], $square);
// => [16, 64] (iteration order is not guaranteed)

$users = [
[ 'user' => 'barney' ],
[ 'user' => 'fred' ]
];

// The `property` iteratee shorthand.
map($users, 'user');
// => ['barney', 'fred']



 use function _\orderBy;

$users = [
['user' => 'fred',   'age' => 48],
['user' => 'barney', 'age' => 34],
['user' => 'fred',   'age' => 40],
['user' => 'barney', 'age' => 36]
]

// Sort by `user` in ascending order and by `age` in descending order.
orderBy($users, ['user', 'age'], ['asc', 'desc'])
// => [['user' => 'barney', 'age' => 36], ['user' => 'barney', 'age' => 34], ['user' => 'fred', 'age' => 48], ['user' => 'fred', 'age' => 40]]



 use function _\partition;

$users = [
['user' => 'barney',  'age' => 36, 'active' => false],
['user' => 'fred',    'age' => 40, 'active' => true],
['user' => 'pebbles', 'age' => 1,  'active' => false]
];

partition($users, function($user) { return $user['active']; })
// => objects for [['fred'], ['barney', 'pebbles']]



 use function _\reduce;

reduce([1, 2], function($sum, $n) { return $sum + $n; }, 0)
// => 3

reduce(['a' => 1, 'b' => 2, 'c' => 1], function ($result, $value, $key) {
if (!isset($result[$value])) {
$result[$value] = [];
}
$result[$value][] = $key;

return $result;
}, [])
// => ['1' => ['a', 'c'], '2' => ['b']] (iteration order is not guaranteed)



 use function _\reduceRight;

$array = [[0, 1], [2, 3], [4, 5]];

reduceRight(array, (flattened, other) => flattened.concat(other), [])
// => [4, 5, 2, 3, 0, 1]



 use function _\reject;

$users = [
['user' => 'barney', 'active' => true],
['user' => 'fred',   'active' => false]
]

reject($users, 'active')
// => objects for ['fred']



 use function _\size;

size([1, 2, 3]);
// => 3

size(new class { public $a = 1; public $b = 2; private $c = 3; });
// => 2

size('pebbles');
// => 7



 use function _\some;

some([null, 0, 'yes', false], , function ($value) { return \is_bool($value); }));
// => true

$users = [
['user' => 'barney', 'active' => true],
['user' => 'fred',   'active' => false]
];

// The `matches` iteratee shorthand.
some($users, ['user' => 'barney', 'active' => false ]);
// => false

// The `matchesProperty` iteratee shorthand.
some($users, ['active', false]);
// => true

// The `property` iteratee shorthand.
some($users, 'active');
// => true



 use function _\sortBy;

$users = [
[ 'user' => 'fred',   'age' => 48 ],
[ 'user' => 'barney', 'age' => 36 ],
[ 'user' => 'fred',   'age' => 40 ],
[ 'user' => 'barney', 'age' => 34 ],
];

sortBy($users, [function($o) { return $o['user']; }]);
// => [['user' => 'barney', 'age' => 36], ['user' => 'barney', 'age' => 34], ['user' => 'fred', 'age' => 48], ['user' => 'fred', 'age' => 40]]

sortBy($users, ['user', 'age']);
// => [['user' => 'barney', 'age' => 34], ['user' => 'barney', 'age' => 36], ['user' => 'fred', 'age' => 40], ['user' => 'fred', 'age' => 48]]



 use function _\now;

now();
// => 1511180325735



 use function _\after;

$saves = ['profile', 'settings'];

$done = after(count($saves), function() {
echo 'done saving!';
});

forEach($saves, function($type) use($done) {
asyncSave([ 'type' => $type, 'complete' => $done ]);
});
// => Prints 'done saving!' after the two async saves have completed.



 use function _\ary;

map(['6', '8', '10'], ary('intval', 1));
// => [6, 8, 10]



 use function _\before;

$users = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
$result = uniqBy(map($users, before(5, [$repository, 'find'])), 'id')
// => Fetch up to 4 results.



 use function _\bind;

function greet($greeting, $punctuation) {
return $greeting . ' ' . $this->user . $punctuation;
}

$object = $object = new class {
public $user = 'fred';
};

$bound = bind('greet', $object, 'hi');
$bound('!');
// => 'hi fred!'



 use function _\bindKey;

$object = new class {
private $user = 'fred';
function greet($greeting, $punctuation) {
return $greeting.' '.$this->user.$punctuation;
}
};

$bound = bindKey($object, 'greet', 'hi');
$bound('!');
// => 'hi fred!'



 use function _\curry;

$abc = function($a, $b, $c) {
return [$a, $b, $c];
};

$curried = curry($abc);

$curried(1)(2)(3);
// => [1, 2, 3]

$curried(1, 2)(3);
// => [1, 2, 3]

$curried(1, 2, 3);
// => [1, 2, 3]

// Curried with placeholders.
$curried(1)(_, 3)(2);
// => [1, 2, 3]



 use function _\delay;

delay(function($text) {
echo $text;
}, 1000, 'later');
// => Echo 'later' after one second.



 use function _\flip;

$flipped = flip(function() {
return func_get_args();
});

flipped('a', 'b', 'c', 'd');
// => ['d', 'c', 'b', 'a']



 use function _\memoize;

$object = ['a' => 1, 'b' => 2];
$other = ['c' => 3, 'd' => 4];

$values = memoize('_\values');
$values($object);
// => [1, 2]

$values($other);
// => [3, 4]

$object['a'] = 2;
$values($object);
// => [1, 2]

// Modify the result cache.
$values->cache->set($object, ['a', 'b']);
$values($object);
// => ['a', 'b']



 use function _\negate;

function isEven($n) {
return $n % 2 == 0;
}

filter([1, 2, 3, 4, 5, 6], negate($isEven));
// => [1, 3, 5]



 use function _\once;

$initialize = once('createApplication');
$initialize();
$initialize();
// => `createApplication` is invoked once



 use function _\overArgs;

function doubled($n) {
return $n * 2;
}

function square($n) {
return $n * $n;
}

$func = overArgs(function($x, $y) {
return [$x, $y];
}, ['square', 'doubled']);

$func(9, 3);
// => [81, 6]

$func(10, 5);
// => [100, 10]



 use function _\partial;

function greet($greeting, $name) {
return $greeting . ' ' . $name;
}

$sayHelloTo = partial('greet', 'hello');
$sayHelloTo('fred');
// => 'hello fred'



 use function _\rest;

$say = rest(function($what, $names) {
return $what . ' ' . implode(', ', initial($names)) .
(size($names) > 1 ? ', & ' : '') . last($names);
});

$say('hello', 'fred', 'barney', 'pebbles');
// => 'hello fred, barney, & pebbles'



 use function _\spread;

$say = spread(function($who, $what) {
return $who . ' says ' . $what;
});

$say(['fred', 'hello']);
// => 'fred says hello'



 use function _\unary;

map(['6', '8', '10'], unary('intval'));
// => [6, 8, 10]



 use function _\wrap;

$p = wrap('_\escape', function($func, $text) {
return '<p>' . $func($text) . '</p>';
});

$p('fred, barney, & pebbles');
// => '<p>fred, barney, &amp; pebbles</p>'



 use function _\eq;

$object = (object) ['a' => 1];
$other = (object) ['a' => 1];

eq($object, $object);
// => true

eq($object, $other);
// => false

eq('a', 'a');
// => true

eq(['a'], (object) ['a']);
// => false

eq(INF, INF);
// => true



 use function _\isEqual;


$object = [ 'a' => 1]
$other = ['a' => '1']

isEqual($object, $other)
// => true

$object === $other
// => false



 use function _\isError;

isError(new \Exception())
// => true

isError(\Exception::Class)
// => false



 use function _\add;

add(6, 4);
// => 10



 use function _\max;

max([4, 2, 8, 6]);
// => 8

max([]);
// => null



 use function _\maxBy;

$objects = [['n' => 1], ['n' => 2]];

maxBy($objects, function($o) { return $o['n']; });
// => ['n' => 2]

// The `property` iteratee shorthand.
maxBy($objects, 'n');
// => ['n' => 2]

bash
$ composer 
php

 use function _\clamp;

clamp(-10, -5, 5)
// => -5

clamp(10, -5, 5)
// => 5

php

 use function _\inRange;

inRange(3, 2, 4)
// => true

inRange(4, 8)
// => true

inRange(4, 2)
// => false

inRange(2, 2)
// => false

inRange(1.2, 2)
// => true

inRange(5.2, 4)
// => false

inRange(-3, -2, -6)
// => true

php

 use function _\random;

random(0, 5)
// => an integer between 0 and 5

random(5)
// => also an integer between 0 and 5

random(5, true)
// => a floating-point number between 0 and 5

random(1.2, 5.2)
// => a floating-point number between 1.2 and 5.2

php

 use function _\get;

$sampleArray = ["key1" => ["key2" => ["key3" => "val1", "key4" => ""]]];
get($sampleArray, 'key1.key2.key3');
// => "val1"

get($sampleArray, 'key1.key2.key5', "default");
// => "default"

get($sampleArray, 'key1.key2.key4', "default");
// => ""

php

 use function _\chain;

$users = [
['user' => 'barney',  'age' => 36],
['user' => 'fred',    'age' => 40],
['user' => 'pebbles', 'age' => 1 ],
];

$youngest = chain($users)
->sortBy('age')
->map(function($o) {
return $o['user'] . ' is ' . $o['age'];
})
->head()
->value();
// => 'pebbles is 1'

php

 use function _\camelCase;

camelCase('Foo Bar')
// => 'fooBar'

camelCase('--foo-bar--')
// => 'fooBar'

camelCase('__FOO_BAR__')
// => 'fooBar'

php

 use function _\capitalize;

capitalize('FRED')
// => 'Fred'

php

 use function _\deburr;

deburr('déjà vu')
// => 'deja vu'

php

 use function _\endsWith;

endsWith('abc', 'c')
// => true

endsWith('abc', 'b')
// => false

endsWith('abc', 'b', 2)
// => true

php

 use function _\escape;

escape('fred, barney, & pebbles')
// => 'fred, barney, &amp pebbles'

php

 use function _\escapeRegExp;

escapeRegExp('[lodash](https://lodash.com/)')
// => '\[lodash\]\(https://lodash\.com/\)'

php

 use function _\kebabCase;

kebabCase('Foo Bar')
// => 'foo-bar'

kebabCase('fooBar')
// => 'foo-bar'

kebabCase('__FOO_BAR__')
// => 'foo-bar'

php

 use function _\lowerCase;

lowerCase('--Foo-Bar--')
// => 'foo bar'

lowerCase('fooBar')
// => 'foo bar'

lowerCase('__FOO_BAR__')
// => 'foo bar'

php

 use function _\lowerFirst;

lowerFirst('Fred')
// => 'fred'

lowerFirst('FRED')
// => 'fRED'

php

 use function _\pad;

pad('abc', 8)
// => '  abc   '

pad('abc', 8, '_-')
// => '_-abc_-_'

pad('abc', 2)
// => 'abc'

php

 use function _\padEnd;

padEnd('abc', 6)
// => 'abc   '

padEnd('abc', 6, '_-')
// => 'abc_-_'

padEnd('abc', 2)
// => 'abc'

php

 use function _\padStart;

padStart('abc', 6)
// => '   abc'

padStart('abc', 6, '_-')
// => '_-_abc'

padStart('abc', 2)
// => 'abc'

php

 use function _\parseInt;

parseInt('08')
// => 8

php

 use function _\repeat;

repeat('*', 3)
// => '***'

repeat('abc', 2)
// => 'abcabc'

repeat('abc', 0)
// => ''

php

 use function _\replace;

replace('Hi Fred', 'Fred', 'Barney')
// => 'Hi Barney'

php

 use function _\snakeCase;

snakeCase('Foo Bar')
// => 'foo_bar'

snakeCase('fooBar')
// => 'foo_bar'

snakeCase('--FOO-BAR--')
// => 'foo_bar'

php

 use function _\split;

split('a-b-c', '-', 2)
// => ['a', 'b']

php

 use function _\startCase;

startCase('--foo-bar--')
// => 'Foo Bar'

startCase('fooBar')
// => 'Foo Bar'

startCase('__FOO_BAR__')
// => 'FOO BAR'

php

 use function _\startsWith;

startsWith('abc', 'a')
// => true

startsWith('abc', 'b')
// => false

startsWith('abc', 'b', 1)
// => true

php

 use function _\template;

// Use the "interpolate" delimiter to create a compiled template.
$compiled = template('hello <%= user %>!')
$compiled([ 'user' => 'fred' ])
// => 'hello fred!'

// Use the HTML "escape" delimiter to escape data property values.
$compiled = template('<b><%- value %></b>')
$compiled([ 'value' => '<script>' ])
// => '<b>&lt;script&gt;</b>'

// Use the "evaluate" delimiter to execute JavaScript and generate HTML.
$compiled = template('<% foreach($users as $user) { %><li><%- user %></li><% }%>')
$compiled([ 'users' => ['fred', 'barney'] ])
// => '<li>fred</li><li>barney</li>'

// Use the internal `print` function in "evaluate" delimiters.
$compiled = template('<% print("hello " + $user)%>!')
$compiled([ 'user' => 'barney' ])
// => 'hello barney!'

// Use backslashes to treat delimiters as plain text.
$compiled = template('<%= "\\<%- value %\\>" %>')
$compiled([ 'value' => 'ignored' ])
// => '<%- value %>'

// Use the `imports` option to import functions or classes with aliases.
$text = '<% all($users, function($user) { %><li><%- user %></li><% })%>'
$compiled = template($text, { 'imports': { '_\each': 'all' } })
$compiled([ 'users' => ['fred', 'barney'] ])
// => '<li>fred</li><li>barney</li>'

// Use custom template delimiters.
\_::$templateSettings['interpolate'] = '{{([\s\S]+?)}}'
$compiled = template('hello {{ user }}!')
$compiled([ 'user' => 'mustache' ])
// => 'hello mustache!'

// Use the `source` property to access the compiled source of the template
template($mainText)->source;

php

 use function _\toLower;

toLower('--Foo-Bar--')
// => '--foo-bar--'

toLower('fooBar')
// => 'foobar'

toLower('__FOO_BAR__')
// => '__foo_bar__'

php

 use function _\toUpper;

toUpper('--foo-bar--')
// => '--FOO-BAR--'

toUpper('fooBar')
// => 'FOOBAR'

toUpper('__foo_bar__')
// => '__FOO_BAR__'

php

 use function _\trim;

trim('  abc  ')
// => 'abc'

trim('-_-abc-_-', '_-')
// => 'abc'

php

 use function _\trimEnd;

trimEnd('  abc  ')
// => '  abc'

trimEnd('-_-abc-_-', '_-')
// => '-_-abc'

php

 use function _\trimStart;

trimStart('  abc  ')
// => 'abc  '

trimStart('-_-abc-_-', '_-')
// => 'abc-_-'

php

 use function _\truncate;

truncate('hi-diddly-ho there, neighborino')
// => 'hi-diddly-ho there, neighbo...'

truncate('hi-diddly-ho there, neighborino', [
'length' => 24,
'separator' => ' '
])
// => 'hi-diddly-ho there,...'

truncate('hi-diddly-ho there, neighborino', [
'length' => 24,
'separator' => '/,? +/'
])
// => 'hi-diddly-ho there...'

truncate('hi-diddly-ho there, neighborino', [
'omission' => ' [...]'
])
// => 'hi-diddly-ho there, neig [...]'

php

 use function _\unescape;

unescape('fred, barney, &amp; pebbles')
// => 'fred, barney, & pebbles'

php

 use function _\upperCase;

upperCase('--foo-bar')
// => 'FOO BAR'

upperCase('fooBar')
// => 'FOO BAR'

upperCase('__foo_bar__')
// => 'FOO BAR'

php

 use function _\upperFirst;

upperFirst('fred')
// => 'Fred'

upperFirst('FRED')
// => 'FRED'

php

 use function _\words;

words('fred, barney, & pebbles')
// => ['fred', 'barney', 'pebbles']

words('fred, barney, & pebbles', '/[^, ]+/g')
// => ['fred', 'barney', '&', 'pebbles']

php

 use function _\attempt;

// Avoid throwing errors for invalid PDO data source.
$elements = attempt(function () {
new \PDO(null);
});

if (isError($elements)) {
$elements = [];
}

php

 use function _\defaultTo;

$a = null;

defaultTo($a, "default");
// => "default"

$a = "x";

defaultTo($a, "default");
// => "x"

php

 use function _\identity;

$object = ['a' => 1];

identity($object) === $object;
// => true