Précédent   Forum des professionnels en informatique > PHP > Scripts
Scripts Forum d'entraide sur les scripts PHP téléchargés. Les meilleurs scripts PHP, la FAQ scripts PHP, toutes les FAQ PHP
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 25/10/2011, 11h26   #1
Invité de passage
 
Inscription : juin 2009
Messages : 4
Détails du profil
Informations personnelles :
Âge : 26
Localisation : France, Rhône (Rhône Alpes)

Informations forums :
Inscription : juin 2009
Messages : 4
Points : 0
Points : 0
Par défaut combinaison de tableau

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
header("Cache-Control: no-cache");
header("Pragma: nocache");
 
require('_config-rating.php');
 
//création des valeur
$vote_sent = preg_replace("/[^0-9]/","",$_REQUEST['j']);
$id_sent = preg_replace("/[^0-9a-zA-Z-]/","",$_REQUEST['q']);
$ip_num = preg_replace("/[^0-9\.]/","",$_REQUEST['t']);
$units = preg_replace("/[^0-9]/","",$_REQUEST['c']);
$ip = $_SERVER['REMOTE_ADDR'];
 
// suprimer le script parce que les utilisateurs normaux ne le verront jamais.
if ($vote_sent > $units) die("Désolé, le vote a l'air d'être sans fondement.");
zeler69 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/10/2011, 12h30   #2
Modérateur
 
Avatar de Benjamin Delespierre
 
Benjamin Delespierre
Développeur Web
Inscription : février 2010
Messages : 2 991
Détails du profil
Informations personnelles :
Nom : Benjamin Delespierre
Âge : 24
Localisation : France

Informations professionnelles :
Activité : Développeur Web
Secteur : High Tech - Opérateur de télécommunications

Informations forums :
Inscription : février 2010
Messages : 2 991
Points : 5 031
Points : 5 031
J'ai une fonction qui calcule le produit cartésien de plusieurs tableau et génère l'intégralité des combinaisons possibles entre tous les éléments de tous les tableaux.

Si c'est effectivement ce que tu cherches, tu peux l'utiliser:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function array_cartesian_product () {
  if (!$c = func_num_args()) return array();
  if ($c == 1) {
    $r = array();
	foreach (func_get_arg(0) as $v) {
		$r[] = array($v);
	}
	return $r;
  }
 
  $args = func_get_args();
  $f = array_shift($args);
  $s = call_user_func_array('array_cartesian_product', $args);
  $r = array();
 
  foreach ($f as $v) {
    foreach ($s as $w) {
	  array_unshift($w, $v);
	  $r[] = $w;
	}
  }
 
  return $r;
}
Exemple:
Code :
1
2
3
4
5
$a = array(1, 5, 4, 3);
$b = array(2, 3);
$c = array(6, 7, 8, 9, 10);
 
var_dump(array_cartesian_product($a,$b,$c));
Résultat:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
array
  0 => 
    array
      0 => int 1
      1 => int 2
      2 => int 6
  1 => 
    array
      0 => int 1
      1 => int 2
      2 => int 7
  2 => 
    array
      0 => int 1
      1 => int 2
      2 => int 8
  3 => 
    array
      0 => int 1
      1 => int 2
      2 => int 9
  4 => 
    array
      0 => int 1
      1 => int 2
      2 => int 10
  5 => 
    array
      0 => int 1
      1 => int 3
      2 => int 6
  6 => 
    array
      0 => int 1
      1 => int 3
      2 => int 7
  7 => 
    array
      0 => int 1
      1 => int 3
      2 => int 8
  8 => 
    array
      0 => int 1
      1 => int 3
      2 => int 9
  9 => 
    array
      0 => int 1
      1 => int 3
      2 => int 10
  10 => 
    array
      0 => int 5
      1 => int 2
      2 => int 6
  11 => 
    array
      0 => int 5
      1 => int 2
      2 => int 7
  12 => 
    array
      0 => int 5
      1 => int 2
      2 => int 8
  13 => 
    array
      0 => int 5
      1 => int 2
      2 => int 9
  14 => 
    array
      0 => int 5
      1 => int 2
      2 => int 10
  15 => 
    array
      0 => int 5
      1 => int 3
      2 => int 6
  16 => 
    array
      0 => int 5
      1 => int 3
      2 => int 7
  17 => 
    array
      0 => int 5
      1 => int 3
      2 => int 8
  18 => 
    array
      0 => int 5
      1 => int 3
      2 => int 9
  19 => 
    array
      0 => int 5
      1 => int 3
      2 => int 10
  20 => 
    array
      0 => int 4
      1 => int 2
      2 => int 6
  21 => 
    array
      0 => int 4
      1 => int 2
      2 => int 7
  22 => 
    array
      0 => int 4
      1 => int 2
      2 => int 8
  23 => 
    array
      0 => int 4
      1 => int 2
      2 => int 9
  24 => 
    array
      0 => int 4
      1 => int 2
      2 => int 10
  25 => 
    array
      0 => int 4
      1 => int 3
      2 => int 6
  26 => 
    array
      0 => int 4
      1 => int 3
      2 => int 7
  27 => 
    array
      0 => int 4
      1 => int 3
      2 => int 8
  28 => 
    array
      0 => int 4
      1 => int 3
      2 => int 9
  29 => 
    array
      0 => int 4
      1 => int 3
      2 => int 10
  30 => 
    array
      0 => int 3
      1 => int 2
      2 => int 6
  31 => 
    array
      0 => int 3
      1 => int 2
      2 => int 7
  32 => 
    array
      0 => int 3
      1 => int 2
      2 => int 8
  33 => 
    array
      0 => int 3
      1 => int 2
      2 => int 9
  34 => 
    array
      0 => int 3
      1 => int 2
      2 => int 10
  35 => 
    array
      0 => int 3
      1 => int 3
      2 => int 6
  36 => 
    array
      0 => int 3
      1 => int 3
      2 => int 7
  37 => 
    array
      0 => int 3
      1 => int 3
      2 => int 8
  38 => 
    array
      0 => int 3
      1 => int 3
      2 => int 9
  39 => 
    array
      0 => int 3
      1 => int 3
      2 => int 10
__________________
A la recherche d'un framework MVC facile a prendre en main ? Essayez Axiom
Nouveau: la référence d'Axiom est disponible sur GitHub (je la peaufine en ce moment même).

Un problème correctement identifié est à moitié résolu, évitez de poster l'intégralité de votre code avec pour seule explication "ça ne marche pas...".
Pour identifier correctement vos problèmes PHP, utilisez la gestion des erreurs et xdebug.

Les boutons et existent, servez-vous en
Benjamin Delespierre est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/10/2011, 14h27   #3
Invité de passage
 
Inscription : juin 2009
Messages : 4
Détails du profil
Informations personnelles :
Âge : 26
Localisation : France, Rhône (Rhône Alpes)

Informations forums :
Inscription : juin 2009
Messages : 4
Points : 0
Points : 0
Par défaut Merci

J'ai 3 tables MySQl :
inscrits_tb => id_inscrits, nom, prenom, etc...
categorie_tb => id_categorie, intitule
inscat_tb => id_inscat, id_inscrit, id_catégorie
zeler69 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/10/2011, 16h18   #4
Modérateur
 
Avatar de Benjamin Delespierre
 
Benjamin Delespierre
Développeur Web
Inscription : février 2010
Messages : 2 991
Détails du profil
Informations personnelles :
Nom : Benjamin Delespierre
Âge : 24
Localisation : France

Informations professionnelles :
Activité : Développeur Web
Secteur : High Tech - Opérateur de télécommunications

Informations forums :
Inscription : février 2010
Messages : 2 991
Points : 5 031
Points : 5 031
Pas de quoi.

J'en ai profité pour me replonger dedans et l'améliorer, voici donc la dernière version:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function array_cartesian_product () {
    if (!$c = func_num_args())
        return array();
 
    if ($c == 1) {
        foreach ((array)func_get_arg(0) as $v)
            $r[] = (array)$v;
        return $r;
    }
 
    $a = func_get_args();
    $f = array_shift($a);
    $s = call_user_func_array(__FUNCTION__, $a);
 
    foreach ((array)$f as $v) {
        foreach ($s as $w) {
            array_unshift($w, $v);
            $r[] = $w;
        }
    }
 
    return $r;
}
Elle permet désormais l'utilisation de types scalaires, ce qui est bien pratique. Voici un exemple:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
 
$couleurs = array('pique', 'trefle', 'coeur ', 'carreau');
 
$cartes = array(2,3,4,5,6,6,7,8,9,10,'valet','dame','roi','as');
 
$paquet = array_map('implode', array_cartesian_product($cartes, ' de ', $couleurs));
 
shuffle($paquet);
 
echo "Première carte tirée: " . array_shift($paquet) . '<br />';
echo "Deuxième carte tirée: " . array_shift($paquet) . '<br />';
echo "Troisième carte tirée: " . array_shift($paquet) . '<br />';
__________________
A la recherche d'un framework MVC facile a prendre en main ? Essayez Axiom
Nouveau: la référence d'Axiom est disponible sur GitHub (je la peaufine en ce moment même).

Un problème correctement identifié est à moitié résolu, évitez de poster l'intégralité de votre code avec pour seule explication "ça ne marche pas...".
Pour identifier correctement vos problèmes PHP, utilisez la gestion des erreurs et xdebug.

Les boutons et existent, servez-vous en
Benjamin Delespierre est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 12h14.


 
 
 
 
Partenaires

Hébergement Web