library arraytopathnamedobject
Converts an array to a path-named object
andrewhathaway/arraytopathnamedobject
Converts an array to a path-named object
- Monday, November 18, 2013
- by AndrewHathaway
- Repository
- 1 Watchers
- 0 Stars
- 12 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 3 Versions
- 0 % Grown
ArrayToPathNamedObject
Converts arrays to objects, but concatenates paths with "_" instead of having object->object. Terrible project to name. Written originally for a friend who didn't want $obj->person->follower->photo
. An exception will be thrown if conflicting keys are the conflicting., (*1)
For example:
When we have $data['person']['follower']['photo']
we can access it like $obj->person_follower_photo
. You can also pass JSON string in and it will return the object., (*2)
Usage:
- Can be installed via Composer.
```PHP
require('ArrayToPathNamedObject.php');, (*3)
try {
$obj = new ArrayToPathNamedObject($json);
} catch(Exception $e) {
die($e);
}, (*4)
````, (*5)
@andrewhathaway, (*6)