PROBLEM WITH ARRAYS!!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Emmash
Forum Newbie
Posts: 13
Joined: Wed Oct 08, 2008 10:49 am

PROBLEM WITH ARRAYS!!!!

Post by Emmash »

Hi,

I'm having a problem with array's functions

//Making the list of the differents arrays
if($cpt_couleur+1<count($_POST["couleur"])){
$liste_tableaux_couleur.=${"tab_resultat_couleur".$cpt_couleur}.",";
}
else{
$liste_tableaux_couleur.=${"tab_resultat_couleur".$cpt_couleur};
}

//Keeping only the numbers that are present in each table
if(count($_POST["couleur"])>1){
$tab_resultat_couleur=array_merge(array_intersect($liste_tableaux_couleur));
}
else{
$tab_resultat_couleur=$liste_tableaux_couleur;
}

The problem is that array_intersect needs 2 parameters to work... I've
also tried with dynamic variables but I think I code the wrong thing 'cause it
didn't solve my problem... Is there any way to just write the content of
the variable $liste_tableaux_couleur in the function array_intersect...
something that would execute the line like :
$tab_resultat_couleur=array_merge(array_intersect($tab_resultat_couleur0,$tab_resultat_couleur1,$tab_resultat_couleur2));
...

Thanks a lot!!!!

Marie-Hélène
Emmash
Forum Newbie
Posts: 13
Joined: Wed Oct 08, 2008 10:49 am

Re: PROBLEM WITH ARRAYS!!!!

Post by Emmash »

I just want to find a way to write the content of the variable

Code: Select all

$liste_tableaux_couleur
in my function

Code: Select all

array_intersect()
to have something like

Code: Select all

array_intersect($table1,$table2,$table3...)


... all the names of tables are in my variable

Code: Select all

$liste_tableaux_couleur
but I can't do

Code: Select all

array_intersect($liste_tableaux_couleur)
, because I get the error that the function needs 2 parameters, is there a way to write the values of my variable directly into the parenthesis of the function????

Code: Select all

$liste_tableaux_couleur
is not an array but a string variable that contains, by example, differents names of tables like

Code: Select all

"$table1,$table2,$table3"

The variable

Code: Select all

$liste_tableaux_couleur
is in a loop because it can contains 2 table or 3 or 4...etc... depending on what the users chose.

Thanks a lot,

Marie-Hélène
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: PROBLEM WITH ARRAYS!!!!

Post by aceconcepts »

Have you looked at: http://uk.php.net/array_intersect

Bon chance :D
Emmash
Forum Newbie
Posts: 13
Joined: Wed Oct 08, 2008 10:49 am

Re: PROBLEM WITH ARRAYS!!!!

Post by Emmash »

Hi everyone,

a man on another forum helps me get my answer.. so here it is :

Code: Select all

eval( '$tab_resultat_couleur = array_merge(array_intersect(' . $liste_tableaux_couleur . '));' );
Have a nice day!

Marie-Hélène
Post Reply