PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.comp.lang.php > intersect not work on array object; is there a solution
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
intersect not work on array object; is there a solution

Réponse
 
LinkBack Outils de la discussion
Vieux 12/07/2007, 13h54   #1
artev
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut intersect not work on array object; is there a solution

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>
  Réponse avec citation
Vieux 12/07/2007, 14h56   #2
ZeldorBlat
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: intersect not work on array object; is there a solution

On Jul 12, 8:54 am, artev <mailnotspa...@notspamm.nn> wrote:
> 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)
>


The solution is to not multi-post.

  Réponse avec citation
Vieux 12/07/2007, 16h10   #3
artev
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: intersect not work on array object; is there a solution

Il Thu, 12 Jul 2007 13:56:44 -0000, ZeldorBlat ha scritto:

> On Jul 12, 8:54 am, artev <mailnotspa...@notspamm.nn> wrote:
>> 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)
>>

>
> The solution is to not multi-post.


I write at php groups (three), but
for this problem, which is the better newsgroup?
  Réponse avec citation
Vieux 12/08/2007, 02h32   #4
Gufo Rosso
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: intersect not work on array object; is there a solution

artev ha scritto:
> 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';



this !is array is obj
if you have 2 value or more in une array
use "bidimensional array" alias of matrix

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


bidimensional array:
$pippo['a'][0] = "pippo0";
$pippo['a'][1] = "pippo2";
$pippo['a'][2] = "pippo2";
$pippo['a'][3] = "pippo3";

or
$pippo['a'] = array("pippo","qui","quo",...)

>
>
> $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>




<?
$array1[0]='a'; // array
$array1[1]='b';
$array1[2]='c';
$array1[3]='d';

class a_rray{
var $me=array();

function intersect_name($value,$value2){
$varname = array_intersect($value,$value2);
$str ="";
foreach($varname as $key =>$value){
$str .= $key." ".$value;
}
return $str;

}


}


$array2[0]='b';
$array2[1]='e';

$cc= new a_rray();
echo $cc->intersect_name($array1,$array2);


please read manual:
array
array_function
class



?>


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 06h13.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14362 seconds with 12 queries