Reply to intersect not work on array object; is there a solution

Your name:

Reply:


Posted by artev on 07/12/07 12:54

if I have 2 array a1 and a2 that are array object: array_intersect not
work; is there a solution? also array_unique not work
(vers. php: 4.3.9)


code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html> <head> <meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">

<?php
$array1[0]->id='a';
$array1[1]->id='b';
$array1[2]->id='c';
$array1[3]->id='d';


$array2[0]->id='b';
$array2[1]->id='e';




$arr_merge=array();
$arr_merge=array_merge($array1, $array2 );

$arr_merge_uniq=array();
$arr_merge_uniq=array_unique($arr_merge);


$arr_intersez_a1_a2=array();
$arr_intersez_a1_a2=array_intersect($array1, $array2 );


$arr_intersez_a2_a1=array();
$arr_intersez_a2_a1=array_intersect($array2, $array1 );




echo "<table border='1' cellpadding='4' cellspacing='0' >";
echo "<tr>";
echo "<td>ARRAY a1</td>";
echo "<td>ARRAY a2</td>";
echo "<td>MERGE</td>";
echo "<td>MERGE <br> UNIQUE</td>";

echo "<td>INTERSECT a1 a2</td>";
echo "<td>INTERSECT a2 a1</td>";
echo "</tr>";

echo "<tr>";
//ARRAY 1
echo "<td valign='top'>";
foreach($array1 as $value) {echo "($value->id)"."<br>";}
echo "</td>";
//ARRAY 2
echo "<td valign='top'>";
foreach($array2 as $value) {echo "($value->id)"."<br>";}
echo "</td>";
//MERGE
echo "<td valign='top'>";
foreach($arr_merge as $value) {echo "($value->id)"."<br>";}
echo "</td>";

//MERGE UNIQUE
echo "<td valign='top'>";
foreach($arr_merge_uniq as $value) {echo "($value->id)"."<br>";}
echo "</td>";

//INTERSECT a1 a2
echo "<td valign='top'>";
foreach($arr_intersez_a1_a2 as $value) {echo "($value->id)"."<br>";}
echo "</td>";

//INTERSECT a2 a1
echo "<td valign='top'>";
foreach($arr_intersez_a2_a1 as $value) {echo "($value->id)"."<br>";}
echo "</td>";

echo "</tr>";
echo "</table>";

?>
</head>
<BODY>

</BODY>
</html>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация