Starting from a Collection, I need to obtain an array of values of a particular field..let me call this field my_id
.
To do this, I use the Varien_Data_Collection::setDataToAll()
on my Collection..in this way:
$collection_fields_array = $collection->setDataToAll(array('my_id'))->toArray(array('my_id'));
..what I obtain is something like this:
Array
(
[0] => Array
(
[my_id] => 71e1bd18
)
[1] => Array
(
[my_id] => 70d47a69
)
[2] => Array
(
[my_id] => 687bed84
)
[3] => Array
(
[my_id] => 673df159
)
[4] => Array
(
[my_id] => 66690a4c
)
[5] => Array
(
[my_id] => 65994440
)
)
But..if my Collection contains a large number of items..setDataToAll()
becomes too time consuming and finally crashes all 2Gb(!!!) of memory...this is because its iteration between all items.
Is another way to obtain an array of field values without this workaround?
In this case,you can use getColumnValues('fieldName')
.
So,try this
$collection->getColumnValues('my_id')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With