Im wondering if array_column keeps the array elements order so when i call the function twice in same array, i can trust the resulting arrays will match. I need to work this way because in the code I have to make many operations with only specific data (one of the keys, in the example, the id), and after all, use both of them (in example id and qty) to insert in db.
Example:
QUERY: SELECT id, qty FROM items ...
CONVERTED INTO ASSOCIATIVE ARRAY:
$array = [
['id' => 1, 'qty' = 2],
['id' => 2, 'qty' = 4]
];
$itemsIds = array_column($array, 'id');
$itemsQty = array_column($array, 'qty');
Can i do?:
for($i = 0; $i < count($array); $i++) {
echo $itemsIds[$i] . $itemsQty[$i];
}
And i will always get the correct data for each item?
array_uniquewhich is stripping duplicate values, which means your two arrays could be two different lengths.array_unique()is an issue because after that arrays may be different lengths. And there doesn't seem to be any reason for doing what you're doing. Can you explain?