compter le nombre de résultat et faire la boucle est 'il plus rapdie que 2 foreach?
Bonjours :),
voici le résultat d'un dump, (on ne connais jamais le nombre de réponse)
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
|
array(24) {
[0] => array(1) {
["nom"] => string(7) "DARAZAC"
}
[1] => array(1) {
["nom"] => string(9) "DARBONNAY"
}
[2] => array(1) {
["nom"] => string(7) "DARBRES"
}
[3] => array(1) {
["nom"] => string(6) "DARCEY"
}
[4] => array(1) {
["nom"] => string(8) "DARDENAC"
}
[5] => array(1) {
["nom"] => string(8) "DARDENAY"
}
[6] => array(1) {
["nom"] => string(6) "DARDEZ"
}
[7] => array(1) {
["nom"] => string(8) "DARDILLY"
}
[8] => array(1) {
["nom"] => string(7) "DAREIZE"
}
[9] => array(1) {
["nom"] => string(7) "DARGIES"
}
[10] => array(1) {
["nom"] => string(8) "DARGNIES"
}
[11] => array(1) {
["nom"] => string(8) "DARGOIRE"
}
[12] => array(1) {
["nom"] => string(8) "DARGOIRE"
}
[13] => array(1) {
["nom"] => string(9) "DARMANNES"
}
[14] => array(1) {
["nom"] => string(7) "DARMONT"
}
[15] => array(1) {
["nom"] => string(6) "DARNAC"
}
[16] => array(1) {
["nom"] => string(8) "DARNETAL"
}
[17] => array(1) {
["nom"] => string(7) "DARNETS"
}
[18] => array(1) {
["nom"] => string(6) "DARNEY"
}
[19] => array(1) {
["nom"] => string(17) "DARNEY AUX CHENES"
}
[20] => array(1) {
["nom"] => string(11) "DARNIEULLES"
}
[21] => array(1) {
["nom"] => string(6) "DAROIS"
}
[22] => array(1) {
["nom"] => string(8) "DARVAULT"
}
[23] => array(1) {
["nom"] => string(6) "DARVOY"
}
} |
pensez vous que ce script est plus rapide que d'avoir 2 foreach encastré ??
Code:
1 2 3 4 5 6 7 8 9
|
Zend_Debug::dump($resultat);
$total_find = count($resultat);
echo $total_find;
for($i=0; $i <$total_find; $i++)
{
echo $resultat[$i]['nom'];
echo "<br>";
} |
je souahite savoir à l'avance combien de donnée il y a dans un tableau, mais je ne sais pas il vaut mieux utiliser ce script pour une question de performance?
Code:
1 2 3 4 5 6 7 8
|
foreach($resultat as $key=>$sousresulstat)
{
foreach($sousresultat as $final
{
echo $final
echo "<br/>";
} |
merci d'avance pour la réponse, si la solution de compter est la plus rapide, je garde cette methode car je la préfère :)