I've noticed a difference in the extract and classicExtract methods of
the Set class. When extracting data from an array that only has one
numeric key set the results aren't the same when using extract and
classicExtract if the numeric key isn't 0. For example:
$data = array(
15 =>
'Post' => array(
'id' => 15,
)
)
$results = Set::extract('/Post/id', $data);
Using extract with xpath syntax $results is an empty array. When using
classicExtract it works either way. However if you have sequential
numeric indexes starting at zero then Set::extract does return
results. There are many times when I use Set::combine to change the
keys of a find operation to the id of whatever is being found.
The below works with both because the numeric key is 0.
$data = array(
0 =>
'Post' => array(
'id' => 15,
)
)
$results = Set::extract('/Post/id', $data);
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en