note 118407 added to function.array-intersect

From: Date: Tue, 01 Dec 2015 20:25:10 +0000
Subject: note 118407 added to function.array-intersect
Groups: php.notes 
Request: Send a blank email to php-notes+get-204256@lists.php.net to get a copy of this message
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)) { ?> ---- Server IP: 72.52.91.14 Probable Submitter: 109.8.180.72 ---- Manual Page -- http://php.net/manual/en/function.array-intersect.php Edit -- https://master.php.net/note/edit/118407 Del: integrated -- https://master.php.net/note/delete/118407/integrated Del: useless -- https://master.php.net/note/delete/118407/useless Del: bad code -- https://master.php.net/note/delete/118407/bad+code Del: spam -- https://master.php.net/note/delete/118407/spam Del: non-english -- https://master.php.net/note/delete/118407/non-english Del: in docs -- https://master.php.net/note/delete/118407/in+docs Del: other reasons-- https://master.php.net/note/delete/118407 Reject -- https://master.php.net/note/reject/118407 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#204256) next »