Created
October 25, 2013 10:07
-
-
Save Taluu/7152427 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $a = $b = ['a' => 'a', | |
| 'b' => new Datetime('10 minutes ago'), | |
| 'c' => ['a' => 'a', | |
| 'b' => new Datetime('20 minutes ago')]]; | |
| $b['b'] = new Datetime('+10 minutes'); | |
| //$b['c']['b'] = new Datetime('+20 minutes'); | |
| $f = function ($a, $b) use (&$f) { | |
| if (gettype($a) !== gettype($b)) { | |
| return 1; | |
| } | |
| if (is_object($a)) { | |
| var_dump($a, $b, spl_object_hash($a), spl_object_hash($b), spl_object_hash($a) === spl_object_hash($b)); | |
| return spl_object_hash($a) === spl_object_hash($b) ? 0 : 1; | |
| } | |
| if (is_array($a)) { var_dump('recursive'); | |
| return [] === array_udiff($b, $a, $f) ? 0 : 1; | |
| } | |
| return $a === $b ? 0 : 1; | |
| }; | |
| $c = array_udiff($b, $a, $f); | |
| // var_dump($c); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // -- var_dump on the spl_object_hash | |
| class DateTime#3 (3) { | |
| public $date => | |
| string(19) "2013-10-25 10:03:59" | |
| public $timezone_type => | |
| int(3) | |
| public $timezone => | |
| string(3) "UTC" | |
| } | |
| class DateTime#1 (3) { | |
| public $date => | |
| string(19) "2013-10-25 09:43:59" | |
| public $timezone_type => | |
| int(3) | |
| public $timezone => | |
| string(3) "UTC" | |
| } | |
| string(32) "000000000603f01b00000000119276c7" | |
| string(32) "000000000603f01900000000119276c7" | |
| bool(false) | |
| // -- var dump on the result | |
| array(2) { | |
| 'b' => | |
| class DateTime#3 (3) { | |
| public $date => | |
| string(19) "2013-10-25 10:16:22" | |
| public $timezone_type => | |
| int(3) | |
| public $timezone => | |
| string(3) "UTC" | |
| } | |
| 'c' => // WTF ? this thing didn't change like AT ALL... | |
| array(2) { | |
| 'a' => | |
| string(1) "a" | |
| 'b' => | |
| class DateTime#2 (3) { | |
| public $date => | |
| string(19) "2013-10-25 09:46:22" | |
| public $timezone_type => | |
| int(3) | |
| public $timezone => | |
| string(3) "UTC" | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment