note 110389 deleted from function.array-diff by cmb

From: Date: Sun, 17 Mar 2019 09:29:15 +0000
Subject: note 110389 deleted from function.array-diff by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210386@lists.php.net to get a copy of this message
Note Submitter: devel-takethisout-oper dot web at gmail dot com ---- Suppose you have a CMS which saves a list of phone numbers for each user. They are stored like this: $phones['Home'] = '(555)555-1234'; $phones['Office'] = '(555)555-2222'; You only want to save to the database if the list of items has changed. Including if the ORDER of them has changed. <?php // Compares two arrays- keys and values (as strings) must match. // Keys and order must be the same to be equal. function arraysEqual($arr1, $arr2){ if(count($arr1) != count($arr2)){ return(FALSE); }else{ $arrStr1 = serialize($arr1); $arrStr2 = serialize($arr2); if( strcmp($arrStr1, $arrStr2)==0 ){ return(TRUE); }else{ return(FALSE); } } } ?>

« previous php.notes (#210386) next »