$t2 = Set::classicExtract($t,'{n}.cd_bibliotem.codiceBiblio')
alternatively:
$t2 = array(null);
foreach($t as $thing)
{
$t2[] = $thing['cd_bibliotem']['codiceBiblio'];
}
Question
I have an array in this structure:
Array (
[0] => Array
(
[cd_bibliotem] => Array
(
[codiceBiblio] => 119179
[codiceTematica] => 3106
)
)
[1] => Array
(
[cd_bibliotem] => Array
(
[codiceBiblio] => 119178
[codiceTematica] => 3106
)
) [...]
I want to have one array with all codiceBiblio
values, I've tried this:
$t = Set::extract($t, '{n}.cd_bibliotem');
But I get:
Array (
[0] => Array
(
[codiceBiblio] => 119179
[codiceTematica] => 3106
) [...]
what's the right syntax to get just the codiceBiblio values?
Solution
$t2 = Set::classicExtract($t,'{n}.cd_bibliotem.codiceBiblio')
alternatively:
$t2 = array(null);
foreach($t as $thing)
{
$t2[] = $thing['cd_bibliotem']['codiceBiblio'];
}
OTHER TIPS
I want to have one array with all codiceBiblio values, I've tried this:
$t = Set::extract($t, '{n}.cd_bibliotem');
The array path specified in the question points at an array - just change the path to point at a specific value, and you'll get a flat array as a return value:
$t = Set::extract($t, '{n}.cd_bibliotem.codiceBiblio');
Which will return:
array(
119179,
119178,
...
)
This is almost identical to the example for both Set::extract and Hash::extract (Hash replaces Set in 2.2, though both exist for backwards-compatibility) in the documentation.