Projects > xArray > Reaching xArray members

Reaching xArray members

Tags:  

"Reaching" xArray members means accessing values of nested members by pattern expressions. You can reach either single (scalar) or multiple values (other xArrays).

Patterns

Patterns can be either deterministic or non-deterministic. Deterministic patterns describe he exact position of the xArray member value you want to access. For an example, these are all deterministic patterns:

0.User.id
1.User.id
2.User.id

Non-deterministic patterns describe the position of values you need relative to another member. For an example, these are all non-deterministic patterns:

{n}.test.blah
{n}.User.id

Reaching single xArray members

You must provide a deterministic pattern in order to reach a single (scalar) value. For an example, suppose we have this xArray:

$a = array(
    array ('User'=>array(
        'id' => 5,
        'name' => 'Ninja',
        'pass' => 'nnj',
    )),
    array ('User'=>array(
        'id' => 12,
        'name' => 'Fat',
        'pass' => 'ninja',
    )),
    array ('User'=>array(
        'id' => 1,
        'name' => 'Ve',
        'pass' => 'bailovity',
    )),
);
$xa = new xArray($a);

To reach the "name" value from the second "User" array ("Fat"), you'd use this pattern:

// 1.User.name = "Fat"
xa->reach('1.User.name');

Reaching multiple xArray members

Using the same xArray as before, you can reach "name" values from all "User" arrays with this pattern:

// {n}.User.name = xArray("Ninja", "Fat", "Ve")
xa->reach('{n}.User.name');


 

0 Comments  Show recent to old
Post a comment


 RSS of this page