note 112734 added to function.in-array
| From: | jemiaymen at gmail dot com | Date: | Thu, 18 Jul 2013 02:53:33 +0000 |
| Subject: | note 112734 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195659@lists.php.net to get a copy of this message | ||
$a = array(1,5,2,15,88,8,7,9,10);
$b = array(4,10,5,11,15);
function similaire($a,$b){
$result = array();
$i =0;
foreach($b as $var){
if(in_array($var,$a)){
$result[$i] = $var;
$i++;
}
}
return $result ;
}
var_dump($a);
var_dump($b);
var_dump(similaire($a,$b));
/*
output
array (size=9)
0 => int 1
1 => int 5
2 => int 2
3 => int 15
4 => int 88
5 => int 8
6 => int 7
7 => int 9
8 => int 10
array (size=6)
0 => int 4
2 => int 10
3 => int 5
4 => int 11
5 => int 15
array (size=4)
1 => int 10
2 => int 5
3 => int 15
*/
----
Server IP: 69.147.83.199
Probable Submitter: 197.6.57.156
----
Manual Page -- http://php.net/manual/en/function.in-array.php
Edit -- https://master.php.net/note/edit/112734
Del: integrated -- https://master.php.net/note/delete/112734/integrated
Del: useless -- https://master.php.net/note/delete/112734/useless
Del: bad code -- https://master.php.net/note/delete/112734/bad+code
Del: spam -- https://master.php.net/note/delete/112734/spam
Del: non-english -- https://master.php.net/note/delete/112734/non-english
Del: in docs -- https://master.php.net/note/delete/112734/in+docs
Del: other reasons-- https://master.php.net/note/delete/112734
Reject -- https://master.php.net/note/reject/112734
Search -- https://master.php.net/manage/user-notes.php