Array PHP, if array changes

izk

Is there a way to execute a code only when my array has a new value passed on in position [0];?

if(?){

print_r(array_values($parcels)[0]);

} else{}

tried multiple statements but all lead to error or invalid. If a new order comes in array[0] gets replaced with that info. So only when that info has changed execute this.. Is this Possible?

Florian

You need to store the old value in an other variable to compare it. So you are able to consider if the value has changed.

$oldValue = $parcels[0];

//-------
//Code that eventually changes the array
//-------

if($oldValue != $parcels[0]) {
    print_r(array_values($parcels)[0]);
    $oldValue = $parcels[0];
} else{}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related