I have an array of values that will get updated periodically. When the array is updated, I want to perform an action using the new values in the updated array.
$old_node->field_name[0]['value'] = 'red'
$old_node->field_name[1]['value'] = 'yellow'
$old_node->field_name[2]['value'] = 'blue'
$updated_node->field_name[0]['value'] = 'green',
$updated_node->field_name[1]['value'] = 'red',
$updated_node->field_name[2]['value'] ='purple',
$updated_node->field_name[3]['value'] = 'blue',
So the values of ‘green’ and ‘purple’ are the new values in the new array. I need to run each of the values that are ADDED to the new array through a function. Something like:
foreach(of the newly added values that are in the new array){
//do stuff;
}
Some values may be deleted when the array is updated, so the the key=>value pairs could change.
I’ve tried:
foreach($updated_node->field_name as $new_value){
if(!in_array($new_value['value'], $old_node->field_name) && $new_value['value'] !== NULL){
//Do stuff;
}
}
But that doesn’t work. I’ve also tried picking out new values with array_diff and array_intersect, but that’s not working either.
use array_diff()
for your new code