note 118407 deleted from function.array-intersect by cmb
| From: | cmb@php.net | Date: | Sun, 09 Feb 2020 08:29:42 +0000 |
| Subject: | note 118407 deleted from function.array-intersect by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-214068@lists.php.net to get a copy of this message | ||
Note Submitter: deekay
----
I ran into a problem (PHP 5.6) with array_intersect(), though i had no idea it was it at the time :
using it properly created an array to string conversion notice, through this type of code (and with
both array variables verified) :
<?php
if(empty($var = array_intersect($array1, $array2))) {
?>
Rewriting its supposed behaviour, even in a rather simple way, removed the notice. Not sure what
caused the function to be unhappy but here's my code that works properly :
<?php
$var = [];
foreach($array1 as $v) {
if(in_array($v, $var)) continue; // value already found
if(in_array($v, $array2)) $var[] = $v;
}
if(empty($var)) {
?>