-
Notifications
You must be signed in to change notification settings - Fork 1
Array API Functionality
This submodule provides functionality to make your job easier when working with arrays. Less code for you is a good thing!
Deeply nested arrays can be tedious to work with, as you need to add, remove, and access the different levels. Dot Notation gives you a simplified approach to filter down to where you need to work with the subject array.
The syntax is:
keyLevel1.keyLevel2.keyLevel3
Notice that each key is separated by a dot (.).
Let's say you are working with a user's dataset and you need to get this person's twitter handle out of the array. You would do: array_get( $user, 'social.twitter' )
;
$user = array(
'user_id' => 504,
'name' => 'Bob Jones',
'social' => array(
'twitter' => '@bobjones',
),
'languages' => array(
'php' => array(
'procedural' => true,
'oop' => false,
),
'javascript' => true,
'ruby' => false,
),
);
What gets returned then is '@bobjones'
;
Credit: Taylor Otwell brought us dot notation in the Laravel framework. Using his concept, Fulcrum adapts it to fit WordPress running on PHP 5.4 and up.
Each of these API helpers is documented in the Wiki.
* indicates this function works with dot notation.
These functions allow you to select the subset of elements you want from the subject array: