473,387 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problems With Arrays!!!

10
Hi,

I'm having a problem with array's functions

Expand|Select|Wrap|Line Numbers
  1. //Making the list of the differents arrays
  2. if($cpt_couleur+1<count($_POST["couleur"])){
  3. $liste_tableaux_couleur.=${"tab_resultat_couleur".$cpt_couleur}.",";
  4. }
  5. else{
  6. $liste_tableaux_couleur.=${"tab_resultat_couleur".$cpt_couleur};
  7. }
  8.  
  9. //Keeping only the numbers that are present in each table
  10. if(count($_POST["couleur"])>1){
  11. $tab_resultat_couleur=array_merge(array_intersect($liste_tableaux_couleur));
  12. }
  13. else{
  14. $tab_resultat_couleur=$liste_tableaux_couleur;
  15. }
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
Oct 8 '08 #1
9 1646
Markus
6,050 Expert 4TB
Hey there, Marie-Hélène.

When posting code on the forums, be sure to use [code] tags. [code] .. code goes here [/code]. If you neglect to do so, you will be given a warning and possibly a temporary ban. Please read the Posting Guidelines on How To Ask A Question

Markus.
Oct 8 '08 #2
Dormilich
8,658 Expert Mod 8TB
I think the problem lies in $liste_tableaux_couleur. make sure this really is an array, otherwise the array functions won't work. right now it seems to be a string (you can check this with var_dump()).

array_intersect() needs 2 input parameters to work. currently you have only one.

regards

PS: add an array element: $your_array[] = $new_element;
Oct 8 '08 #3
Emmash
10
I just want to find a way to write the content of the variable $liste_tableaux_couleur in my function
[PHP]array_intersect()[/PHP] to have something like [PHP]array_intersect($table1,$table2,$table3...)[/PHP]... all the names of tables are in my variable [PHP]$liste_tableaux_couleur [/PHP] but I can't do [PHP]array_intersect($liste_tableaux_couleur)[/PHP], 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????

[PHP]$liste_tableaux_couleur[/PHP] is not an array but a string variable that contains, by example, differents names of tables like [PHP]"$table1,$table2,$table3"[/PHP]

The variable [PHP]$liste_tableaux_couleur[/PHP] 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
Oct 8 '08 #4
Dormilich
8,658 Expert Mod 8TB
I see 2 (at least) posibilities
#1 merge all arrays an make the result unique
[PHP]$liste_tableaux_couleur = array();
while ($count < $limit) {
$liste_tableaux_couleur = array_merge($liste_tableaux_couleur, ${"table" . $count});
$count++;
}
$tab_resultat_couleur = array_unique($liste_tableaux_couleur);[/PHP]
# 2 use the eval() function
[PHP]$expression = '$tab_resultat_couleur = array_merge( array_intersect(' . $liste_tableaux_couleur . ') )';
eval( $expression );[/PHP]
regards
Oct 8 '08 #5
Emmash
10
I use your second proposition :

[PHP]eval('$tab_resultat_couleur=array_merge(array_inte rsect('.$liste_tableaux_couleur.'))');[/PHP]

but I get the error Parse error: syntax error, unexpected $end in ...(363) : eval()'d code on line 1

Do you have any idea?
Oct 8 '08 #6
Dormilich
8,658 Expert Mod 8TB
oh, I forgot the ; at the end of the string. ...stupid me
[PHP]
eval( '$tab_resultat_couleur = array_merge(array_intersect(' . $liste_tableaux_couleur . '));' );[/PHP]
Oct 8 '08 #7
pbmods
5,821 Expert 4TB
Heya, Marie-Hélène.

Try this, instead:

Expand|Select|Wrap|Line Numbers
  1. $tab_resultat_couleur = array_merge(call_user_func_array('array_intersect', $liste_tableaux_couleur));
  2.  
http://php.net/call_user_func_array
Oct 9 '08 #8
Emmash
10
Wow Dormilich, that works very well!!! I didn't know we can use the function eval in php like in javascript.... Thanks a lot for your help!!!

Have a nice day!

Marie-Hélène
Oct 9 '08 #9
Dormilich
8,658 Expert Mod 8TB
I didn't know we can use the function eval in php like in javascript....
Salut Marie-Hélène,

the PHP developers had obviously a good reason to call their function eval()..... *g*

Dormi ← glad to be of help
Oct 9 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: -Steve- | last post by:
Okay I have a bunch of code below. Hope it comes across readable. The problem I'm having is that in the lines under main(): cout << a << endl; Is going into the code for IntArray(const...
13
by: muser | last post by:
for the following code: strncpy(temp_issue, &temp1, 4); files.rec1.issue_rec = atol(temp_issue); cout<<files.rec1.issue_rec<<endl; on execution I get the following. 0x0fd10 a memory...
12
by: Duderonomoy | last post by:
Hello, I am querying the JavaScript community to learn if others are having problems with Safari and JavaScript arrays: myImages = ; then referenced like this:
4
by: Wayne Wengert | last post by:
I am still stuck trying to create a Class to use for exporting and importing array data to/from XML. The format of the XML that I want to import/export is shown below as is the Class and the code I...
7
by: jmac | last post by:
Greetings fellow programmers, I have created a C program that has a few bugs and would like to get some help with working them out. Here is a list of the problems that I am experiencing: -...
9
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the...
5
by: Alan Howard | last post by:
We're getting "ERROR (0x8007000E) Not enough storage is available to complete this operation" errors on a fairly large, busy ASP/SQL Server web site. The error is being thrown on a line calling...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
152
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { {...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.