PHP/Data Structure/array diff — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 07:02, 26 мая 2010
Array Complement
<?php
$first = array("e", "h", "r", "j", "b");
$last = array("w", "e", "c");
$diff = array_diff($last, $first);
echo "<p>";
foreach ($diff as $v) { echo "{$v} "; }
echo "</p>\n";
?>
array_diff
<?php
$array1 = array("OH","CA","NY","HI","CT");
$array2 = array("OH","CA","HI","NY","IA");
$array3 = array("TX","MD","NE","OH","HI");
$diff = array_diff($array1, $array2, $array3);
print_r($intersection);
?>
array_diff( ) function returns a new array containing all the values of array $arr1 that do not exist in array $arr2.
array array_diff ( array arr1, array arr2 [, array ...] )
<?
$toppings1 = array("Pepperoni", "Cheese", "Anchovies", "Tomatoes");
$toppings2 = array("Ham", "Cheese", "Peppers");
$diff_toppings = array_diff($toppings1, $toppings2);
var_dump($diff_toppings);
?>