note 110389 added to function.array-diff

From: Date: Wed, 17 Oct 2012 15:31:40 +0000
Subject: note 110389 added to function.array-diff
Groups: php.notes 
Request: Send a blank email to php-notes+get-191353@lists.php.net to get a copy of this message
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); } } } ?> ---- Server IP: 69.147.83.199 Probable Submitter: 173.206.12.160 ---- Manual Page -- http://www.php.net/manual/en/function.array-diff.php Edit -- https://master.php.net/note/edit/110389 Del: integrated -- https://master.php.net/note/delete/110389/integrated Del: useless -- https://master.php.net/note/delete/110389/useless Del: bad code -- https://master.php.net/note/delete/110389/bad+code Del: spam -- https://master.php.net/note/delete/110389/spam Del: non-english -- https://master.php.net/note/delete/110389/non-english Del: in docs -- https://master.php.net/note/delete/110389/in+docs Del: other reasons-- https://master.php.net/note/delete/110389 Reject -- https://master.php.net/note/reject/110389 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#191353) next »