note 129705 added to function.array-diff
| From: | yo@aaron.com.es | Date: | Wed, 14 Aug 2024 06:40:06 +0000 |
| Subject: | note 129705 added to function.array-diff | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221478@lists.php.net to get a copy of this message | ||
Looks like when one of the given arrays is multidimensional this will throw a warning:
PHP Warning: Array to string conversion in Command line code on line 1
Sharing here, because it was not obvious for me from the error nor the documentation in this page.
Code:
<?php
php -r 'array_diff(["a" => 1], ["b" => [ 1 ]]);'
?>
Result:
PHP Warning: Array to string conversion in Command line code on line 1
Warning: Array to string conversion in Command line code on line 1
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 2a0c:5a84:8201:a900:6d9b:813a:5db0:d2f2)
----
Manual Page -- https://php.net/manual/en/function.array-diff.php
Edit -- https://main.php.net/note/edit/129705
Del: integrated -- https://main.php.net/note/delete/129705/integrated
Del: useless -- https://main.php.net/note/delete/129705/useless
Del: bad code -- https://main.php.net/note/delete/129705/bad+code
Del: spam -- https://main.php.net/note/delete/129705/spam
Del: non-english -- https://main.php.net/note/delete/129705/non-english
Del: in docs -- https://main.php.net/note/delete/129705/in+docs
Del: other reasons-- https://main.php.net/note/delete/129705
Reject -- https://main.php.net/note/reject/129705
Search -- https://main.php.net/manage/user-notes.php