note 91651 modified in function.array-intersect by danbrown
| From: | danbrown@php.net | Date: | Mon, 22 Jun 2009 12:50:59 +0000 |
| Subject: | note 91651 modified in function.array-intersect by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-157228@lists.php.net to get a copy of this message | ||
i wrote this one to get over the problem i found in getting strings intersected instead of arrays as
there is no function in php.
<?php
function matched_main_numbers($string, $string2)
{
$string = "04 16 17 20 29";
$arr1 = explode(" ", $string);
$string2 = "45 34 04 29 16";
$arr2 = explode(" ", $string2);
$array = array_intersect($arr1, $arr2);
$comma_separated = implode($array);
$str = $comma_separated;
$balls = "$comma_separated";
$matched_balls = chunk_split($balls,2," ");
$matched_balls =" $matched_balls";
$number_of_matched_main_balls = strlen($str);
$number_of_matched_main_balls = ($number_of_matched_main_balls/2);
$numbers = "You matched $number_of_matched_main_balls main balls";
return $numbers;
}
?>
--was--
i wrote this one to get over the problem i found in getting strings intersected instead of arrays as
there is no function in php.
[php]
function matched_main_numbers($string, $string2)
{
$string = "04 16 17 20 29";
$arr1 = explode(" ", $string);
$string2 = "45 34 04 29 16";
$arr2 = explode(" ", $string2);
$array = array_intersect($arr1, $arr2);
$comma_separated = implode($array);
$str = $comma_separated;
$balls = "$comma_separated";
$matched_balls = chunk_split($balls,2," ");
$matched_balls =" $matched_balls";
$number_of_matched_main_balls = strlen($str);
$number_of_matched_main_balls = ($number_of_matched_main_balls/2);
$numbers = "You matched $number_of_matched_main_balls main balls";
return $numbers;
}
[php]
http://php.net/manual/en/function.array-intersect.php