I have an array of objects where the reference is not the same as the code_cip.
Array (
[9921279] => lignecatalogue Object ( [id] => 3013181 [reference] => 9921279 [commentaire] => [code_cip] => 9884064 )
[9884064] => lignecatalogue Object ( [id] => 3013193 [reference] => 9884064 [commentaire] => [code_cip] => 9884064 )
)
What i am trying to accomplish is to update only the [reference] => 9921279 on the first item to [reference] => 9884064. The [reference] will be updated only if it is not equal to its code_cip. So far i am stuck on the code below.
$arrLigneCats = getAllCat(); //returns above array
foreach($arrLigneCats as $ligneCat) {
if ($ligneCat->code_cip != $ligneCat->reference) {
$reference = $ligneCat->reference;
} else {
$reference = $ligneCat->code_cip;
}
}
Anyone has any idea of how to replace the key without the removing the entire line?
reference$ligneCatby reference, like thisforeach($arrLigneCats as &$ligneCat) {$ligneCat->reference = $ligneCat->code_cip;