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
bitdeli git github stats

php-login goes #2 PHP script worldwide in BitDeli stats

Holy! I just checked the stats of my little php-login hobby project on BitDeli (the tracking service for GitHub) and

Compare 250+ cloud server plans with Cloud Cost Calculator

How cool is that ? The Cloud Cost Calculator compares more than 250 cloud server plans of Amazon, Rackspace, DigitalOcean,

vagrant

How to setup a (or multiple) server/LAMP-stack inside a virtual machine for local development with Vagrant and PuPHPet

You know this: You need a new server, something to develop on, something to test on, something to put your

shadow dom

A quick video introduction into Shadow-DOM, the game-changing DOM-subtree-technology

Awesome talk by Eric Bidelman (of the Chrome team): Shadow-DOM was often heard in 2013 and seem to exist for

angular js

Learn AngularJS in 20 (or 90) minutes with Dan Wahlin

Definitly two of the best and most up-to-date short-introductions into AngularJS: Dan Wahlin shows how to build a full little

dev coding cards deck

Nice gifts for devs: Nerdy playing-cards decks

Wonderful idea: Playing cards decks for developers. No, not scrum-cards, more the classic stuff. Code:deck $10 plus $5 for shipping

forbes 30 under 30

Need motivation ? Check out these 2 awesome “FORBES 30 under 30” lists (web, UI, games)

The FORBES magazine has just published the new “30 under 30” lists, and they are really really interesting! Lots of

js javascript

JavaScript Testing Tactics (21min video by Justin Searls)

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

New project: Building a naked PHP skeleton / boilerplate application from scratch

[This post is from November 2013. In the meantime (I’m writing this in November 2014) the project has changed its

1/4

Categories

Search

php
How to use the PHP 5.5 password hashing functions
Hacking ATMs – A conference talk about the current security state of Windows XP driven cash machines
php-phalcon-logo
Which PHP-framework to learn in 2014 ? PHALCON, by far the fastest ever!
php
Awesome list of Design Patterns with PHP code examples
pdo-debug
Debug PDO with this one-line function. Yeah!
phpstorm-8
PHPStorm 8 has just been released
java vs php
Switching from Java to PHP. Seriously. A very interesting and pre-judice-free talk with Ph.D. Aris Zakinthinos
vagrant
How to copy Vagrant boxes (or duplicate them)
mod-rewrite-ubuntu-14-04-lts
EOL lists of Ubuntu, Debian and CentOS for your server plannings
php uk conference
Profiling PHP Applications by Bastian Hofmann (video from PHP UK Conference 2014)
atomic-design
An introduction into Atomic Design, a super-clean way to style web applications
Test GZIP compression of your server easily
sass laravel
Extremely easy SASS in Laravel (with pure PHP)
sass
New features in SASS 3.3 (a talk by SASS-creator Chris Eppstein)
css
How to center a div vertically and horizontally (modern methods, without fixed size!)

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