Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD > PHP & MySQL
PHP & MySQL Forum d'entraide sur les fonctions MySQL avec PHP. Avant de poster -> FAQ MySQL, Cours MySQL et Sources MySQL. Pour les questions concernant le moteur MySQL plutôt que les fonctions PHP, merci d'utiliser le forum MySQL.
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 28/08/2011, 14h47   #1
Membre régulier
 
Inscription : juillet 2004
Messages : 92
Détails du profil
Informations forums :
Inscription : juillet 2004
Messages : 92
Points : 75
Points : 75
Par défaut problème de données invisible sur un return et visible avec var_dump()

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
 
function kick_doublon($lastArray,$arrId) {
		$reduceArray = $lastArray[0];
		$lastArray = $reduceArray;
	switch (gettype($lastArray)){
		case "array" :
			$cLA = count($lastArray);
			if($cLA == intval(1)){
				kick_doublon($lastArray,$arrId);
			}else{
				echo 'non kicked';
			for($i=0;$cLA>$i;$i++){
				if($lastArray[$i] != "" && is_array($lastArray))
					$arr[$lastArray[$i][$arrId]] = array($lastArray[$i][$arrId]=>$lastArray[$i]);
					$arr++;
			}
			//ksort($arr);
			return $arr;
			}
		break;
		case "object" :
			if(is_object($lastArray)){
				foreach ($lastArray as $key){
					foreach ($key as $k => $v){
					$arr[$key->$arrId] = array($key->$arrId => $key);
					$arr++;
					}
				}
			}
			ksort($arr);
			return $arr;
		break;
	}
 
}
$tab[] = array(
				array("id"=>"1","nom"=>"test","prenom"=>"gege","age"=>"38","status"=>utf8_encode("père")),
				array("id"=>"22","nom"=>"test","prenom"=>"nina","age"=>"32","status"=>utf8_encode("mère")),
				array("id"=>"22","nom"=>"test","prenom"=>"nina","age"=>"32","status"=>utf8_encode("mère")),
				array("id"=>"22","nom"=>"test","prenom"=>"nina","age"=>"32","status"=>utf8_encode("mère")),
				array("id"=>"333","nom"=>"test","prenom"=>utf8_encode("bill"),"age"=>"10","status"=>"fils"),
				array("id"=>"4444","nom"=>"test","prenom"=>"lola","age"=>"6","status"=>"fille"),
				array("id"=>"55555","nom"=>"test","prenom"=>"julia","age"=>"6","status"=>"fille"));
$test =  array($tab);
var_dump(kick_doublon($test,'id'));//return null ici mais si on var_dump on a le tableaux trié
$test1 = $tab;
var_dump(kick_doublon($test1,'id')); // ce test marche
 
Merci de votre aide.
headmax est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/08/2011, 15h33   #2
Rédacteur
 
Avatar de jreaux62
 
Homme Jérôme Réaux
Webdesigner
Inscription : août 2008
Messages : 2 993
Détails du profil
Informations personnelles :
Nom : Homme Jérôme Réaux
Âge : 45
Localisation : France, Pas de Calais (Nord Pas de Calais)

Informations professionnelles :
Activité : Webdesigner
Secteur : Arts - Culture

Informations forums :
Inscription : août 2008
Messages : 2 993
Points : 5 786
Points : 5 786
Envoyer un message via Skype™ à jreaux62
Bonjour,
c'est demandé si gentiment ...

affiche ca, tu comprendras :
Code :
1
2
3
4
5
<?php
echo '<pre>';
print_r($tab);
echo '</pre>';
?>
__________________
"Ce qui se conçoit bien s'énonce clairement - Et les mots pour le dire arrivent aisément."
Nicolas Boileau-Despréaux, Homme de lettres français (1636-1711), principal théoricien de l'esthétique classique.
Site perso Mes tutos DVP : Gestion-Affichage de Nouvelles - Affichage en tableau HTML - Fonctions de redimensionnement d'images
jreaux62 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/08/2011, 16h31   #3
Membre régulier
 
Inscription : juillet 2004
Messages : 92
Détails du profil
Informations forums :
Inscription : juillet 2004
Messages : 92
Points : 75
Points : 75
Citation:
Envoyé par jreaux62 Voir le message
Bonjour,
c'est demandé si gentiment ...

affiche ca, tu comprendras :
Code :
1
2
3
4
5
<?php
echo '<pre>';
print_r($tab);
echo '</pre>';
?>
Salut mon $test1 le fait dans le code je comprend pas ta réponse, normalement il devrait affiché les deux tests.
Désolé de n'avoir pas saisit ta réponse.
headmax est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/08/2011, 00h06   #4
Rédacteur
 
Avatar de jreaux62
 
Homme Jérôme Réaux
Webdesigner
Inscription : août 2008
Messages : 2 993
Détails du profil
Informations personnelles :
Nom : Homme Jérôme Réaux
Âge : 45
Localisation : France, Pas de Calais (Nord Pas de Calais)

Informations professionnelles :
Activité : Webdesigner
Secteur : Arts - Culture

Informations forums :
Inscription : août 2008
Messages : 2 993
Points : 5 786
Points : 5 786
Envoyer un message via Skype™ à jreaux62
$tab[] = array(...); ou $tab[0] = array(...); ca revient au même ici.
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
<?php
$tab[0] = array(
				array("id"=>"1","nom"=>"test","prenom"=>"gege","age"=>"38","status"=>utf8_encode("père")),
				array("id"=>"22","nom"=>"test","prenom"=>"nina","age"=>"32","status"=>utf8_encode("mère")),
				array("id"=>"22","nom"=>"test","prenom"=>"nina","age"=>"32","status"=>utf8_encode("mère")),
				array("id"=>"22","nom"=>"test","prenom"=>"nina","age"=>"32","status"=>utf8_encode("mère")),
				array("id"=>"333","nom"=>"test","prenom"=>utf8_encode("bill"),"age"=>"10","status"=>"fils"),
				array("id"=>"4444","nom"=>"test","prenom"=>"lola","age"=>"6","status"=>"fille"),
				array("id"=>"55555","nom"=>"test","prenom"=>"julia","age"=>"6","status"=>"fille"));
$test =  array($tab);
//var_dump(kick_doublon(array($tab),'id'));//return null ici mais si on var_dump on a le tableaux trié
$test1 = $tab;
//var_dump(kick_doublon($tab,'id')); // ce test marche
 
echo '<br />$tab :<pre>';
print_r($tab[0]);
echo '</pre>';
 
echo '<br />kick_doublon($tab) :<pre>';
print_r(kick_doublon($tab,'id'));
echo '</pre>';
 
echo '<br />kick_doublon(array($tab)) :<pre>';
print_r(kick_doublon(array($tab[0]),'id'));
echo '</pre>';
?>
__________________
"Ce qui se conçoit bien s'énonce clairement - Et les mots pour le dire arrivent aisément."
Nicolas Boileau-Despréaux, Homme de lettres français (1636-1711), principal théoricien de l'esthétique classique.
Site perso Mes tutos DVP : Gestion-Affichage de Nouvelles - Affichage en tableau HTML - Fonctions de redimensionnement d'images
jreaux62 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 14h29.


 
 
 
 
Partenaires

Hébergement Web