Array manipulation/traversal #46

Closed
opened 2014-05-14 20:30:57 +00:00 by geoffoliver · 2 comments
geoffoliver commented 2014-05-14 20:30:57 +00:00 (Migrated from github.com)

I'd like to be able to do the following...

$arr = array(
    'Product'=>array(
        'id'=>'1',
        'name'=>'A Product'
    )
);
echo Array::get('Product.id', $arr); 
// "1";

$arr2 = array(
    array(
        'Product'=>array('id'='1')
    ),array(
        'Product'=>array('id'=>'2')
    )
);
var_dump(Array::get('\d.Product.id'));
// array('1','2')

$arr3 = array(
    array(
        'Product'=>array('id'=>'1','name'=>'Product 1')
    ),
    array(
        'Product'=>array('id'=>'2','name'=>'Product 2')
    )
);
var_dump(Array::map('\d.Product.id','\d.Product.name',$arr3));
// array('1'=>'Product 1','2'=>'Product 2')

More useful things/examples - http://api.cakephp.org/2.5/class-Hash.html

I'd like to be able to do the following... ``` php $arr = array( 'Product'=>array( 'id'=>'1', 'name'=>'A Product' ) ); echo Array::get('Product.id', $arr); // "1"; $arr2 = array( array( 'Product'=>array('id'='1') ),array( 'Product'=>array('id'=>'2') ) ); var_dump(Array::get('\d.Product.id')); // array('1','2') $arr3 = array( array( 'Product'=>array('id'=>'1','name'=>'Product 1') ), array( 'Product'=>array('id'=>'2','name'=>'Product 2') ) ); var_dump(Array::map('\d.Product.id','\d.Product.name',$arr3)); // array('1'=>'Product 1','2'=>'Product 2') ``` More useful things/examples - http://api.cakephp.org/2.5/class-Hash.html
joshtronic commented 2014-09-27 11:07:22 +00:00 (Migrated from github.com)

@geoffoliver Thoughts on this being a separate library?

I'm slowly moving in the direction that Pickles will simply be this core system, then anything not being used by the code could be offloaded to separate projects that could be loaded in with composer. More of a Pickles Component or Plugin system 📦

@geoffoliver Thoughts on this being a separate library? I'm slowly moving in the direction that Pickles will simply be this core system, then anything not being used by the code could be offloaded to separate projects that could be loaded in with composer. More of a Pickles Component or Plugin system :package:
geoffoliver commented 2014-09-27 20:58:46 +00:00 (Migrated from github.com)

It would make sense as a separate component/library/whatever. uses Pickles\ArrayUtil

It would make sense as a separate component/library/whatever. uses Pickles\ArrayUtil
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
joshtronic/pickles#46
No description provided.