Logo
  • PHP
    • HipHop / HHVM
    • Modern PHP
    • PHPStorm
    • LAMP
    • Laravel
    • Composer
    • PDO
  • JavaScript
    • node.js
    • AngularJS
  • CSS
    • SASS
    • “CSS4” (CSS level 4)
  • HTML
  • Git
  • LAMP
  • Vagrant
  • UI / UX
  • Architecture of …
  • Off-Topic
With ♥ from Berlin
May 12, 2014
Chris
PHP
Comments Off on “Belt” adds very clever everyday functions to PHP, comes with JavaScript naming styles and eventually solves the needle/haystack problem

“Belt” adds very clever everyday functions to PHP, comes with JavaScript naming styles and eventually solves the needle/haystack problem

PreviousNext
php

This little projects is basically super-simple, but somehow really really clever and definitly a time-saver: Belt is a typical Composer-loaded dependency that adds a lot of useful functions “to PHP”. Some of these functions are more or less duplicates of already existing one in native PHP, buuuut they solve the common unsteady needle / haystack vs. haystack /needle parameter-order problem in PHP (and narrow to the beautiful Java / JavaScript function/method naming convention). A very interesting project, hopefully with a great future! Let’s see some examples (some examples show callable code, some show method definitions):

// returns the max value of an array
Belt::max([1, 2, 3]); // => 3

// checks if arguments are equal
Belt::isEqual("yeah", "nope"); // => false

// flattens a multi-dimensional array
Belt::flatten([1, [2, [3]]]) // => [1, 2, 3]

// create an array containing a range of elements, optional with steppings
Belt::range(1, 10, 2); // => 1, 3, 5, 7, 9

// returns an array containing the unique items in both arrays
union($array1, $array2)

// execute $closure only once and ignore future calls [interesting stuff!]
once(Closure $closure)

// only execute $closure after the exact $number of failed tries
after($number, Closure $closure)

// escape all HTML entities in a string
escape($string)

// invoke a $closure $number of times
times($number, Closure $closure)

// iterate through $collection using $iterator
each(array $collection, Closure $iterator)

// convert $value to an array
toArray($value)

// group values in $collection by $iterator's return value
groupBy(array $collection, Closure $iterator)

// determine whether the given object has a key
has($object, $key)

// copy all properties from $source to $destination
extend($source, $destination)

// fill in any missing values using $defaults
defaults($object, $defaults)

// determine whether the given value is a float or an integer
isNumber($value)

Link: Belt on GitHub

belthaystackmethodnamesnaming conventionsneedlePHP
Share this
php

A super-simple introduction into PHP namespaces (7min video)

Once again, Jesse of JREAM totally nails it right on the head. A super-simple introduction into PHP namespaces. If you

composer

How to install Composer on Windows 7 / 8 or Ubuntu

Installation on Windows 7 / 8 Installing Composer on Windows 7 or 8 is extremely easy: Get the latest version

(Links) How to fix an extremely slow Symfony inside a Vagrant box

When you work with Vagrant (if not – try it!) on a Windows or Mac machine (which is an excellent

O’Reilly’s Learning JavaScript Design Patterns by Addy Osmani for free

Addy Osmani has published his excellent book Learning JavaScript Design Patterns for free! You can read the entire book including

hiphop php

Vote for “Hack” for HipHop/HHMV support (future style PHP) in PHPStorm 8

“Hack” will come. And “Hack” will change PHP, definitly. In case you never heard of it, have a look into

php uk conference

PHP Opcache Explained by Julien Pauli (video from PHP UK Conference 2014)

The title says it all. A VERY deep explanation on how OpCache works. If you never heard of this excellent

php-7

PHP 6.0 will be PHP 7

Germany’s excellent PHP Magazin just posted interesting news: The next major version of PHP will be PHP 7, the development

php uk conference

PHP Caching Best Practices by Eli White (video from PHP UK Conference 2014)

The title says it all: PHP Caching best practices.

[Link] Redesigning SoundCloud by Evan Simoni

Again, an interesting approach / proof-of-concept on a redesign of a major website. Evan Simoni has overthought SoundCloud’s UI and

php

How to use the PHP 5.5 password hashing functions

PHP 5.5 introduced some very interesting password hashing functions that will make your life much much easier, the web much

1/4

Categories

Search

This is an experimental advertisement
php-legacy-code
Interesting talk on modernizing a legacy PHP codebase
shadow dom
A quick video introduction into Shadow-DOM, the game-changing DOM-subtree-technology
MINI, an extremely simple barebone PHP application
cheap cloud server php
DigitalOcean rolls out interesting feature: Transfering server snapshots directly to the client’s account
sass laravel
Extremely easy SASS in Laravel (with pure PHP)
offf-2014
Europeans: Get ready for OFFF conference / festival in Barcelona, May 2014
zend framework 3
First view on Zend Framework 3 by Matthew O’Phinney
PHPMyAdmin not found after installation ? Here’s a fix (Ubuntu 12.04) !
Disappointed by Watch Dogs’s graphics ? See how it looks with unlocked, hidden settings. Awesome!
java vs php
Switching from Java to PHP. Seriously. A very interesting and pre-judice-free talk with Ph.D. Aris Zakinthinos
java
Interesting: code of the same application in PHP, Python, Ruby, Closure, node.js, Java and Go
increase-your-pagespeed-score
Increase your PageSpeed score (10min video with Matt Gaunt)
sass
New features in SASS 3.3 (a talk by SASS-creator Chris Eppstein)
(Links) How to fix an extremely slow Symfony inside a Vagrant box

Tags

apache bash centos composer conference coupon CSS debian fonts framework git GitHub hack HHVM HipHop HTML HTML5 IDE JavaScript JS LAMP laravel linux mod_rewrite MVC MySQL Nginx optimization PHP PHP 5.5 PHP 5.6 phpmyadmin PHPStorm security server SSD Ubuntu UI UX vagrant video virtual machine voucher VPS wordpress
Side-Project: Wordle-Solver:
www.wordle-helper.info

Pages

  • Privacy Policy