In_array avec require....

Résolu
Jeje_ Messages postés 14 Date d'inscription vendredi 27 février 2004 Statut Membre Dernière intervention 7 octobre 2005 - 9 août 2005 à 14:57
Jeje_ Messages postés 14 Date d'inscription vendredi 27 février 2004 Statut Membre Dernière intervention 7 octobre 2005 - 9 août 2005 à 16:13
Voila j'ai un soucis de tableau (le tableau est contenu dans un
require) ou j'arrive pas à tester si la valeur est contenu dans le
tableau ou non



mon code :



<?php

$art = $_GET["art"];

$tit = 'TITREARTICLE'."$art".'_PRESSE';

$arti = 'ARTICLE'."$art".'PRESSE';

require("fr-lang.php");



if(in_array($tit, $titres)) {

echo "Trouvé !";

}

else

{

echo "non trouvé";

}



ca me met toujours non trouvé même si c'est effectivement dans le tableau titres (du fichier fr-lang donc)

4 réponses

arnal69130 Messages postés 445 Date d'inscription lundi 17 février 2003 Statut Membre Dernière intervention 22 mars 2007 2
9 août 2005 à 15:37
Pour commencer, remplace
if ($art = null)
par
if ($art == null)
sinon, $art vaudra tjs null...

Ensuite, $titres est un tableau associatif, alors je ne pense pas que in_array soit la bonne fonction.
Essaie plutôt
array_key_exists($tit,$titres);
http://www.php.net/manual/fr/function.array-key-exists.php

Arn;o)
3
arnal69130 Messages postés 445 Date d'inscription lundi 17 février 2003 Statut Membre Dernière intervention 22 mars 2007 2
9 août 2005 à 15:08
Si tu ne nous donnes pas tout le code, on ne peut pas deviner où est le problème ! Et notamment, comment est défini le tableau ?
0
Jeje_ Messages postés 14 Date d'inscription vendredi 27 février 2004 Statut Membre Dernière intervention 7 octobre 2005
9 août 2005 à 15:16
le fichier en question :



<?php

$art = $_GET["art"];

$tit = 'TITREARTICLE'."$art".'_PRESSE';

$arti = 'ARTICLE'."$art".'PRESSE';

require("fr-lang.php");

if ($art = null)

{

}

else

{

$tit2 = $tit;

$arti2 = $arti;

}

if(in_array($tit, $titres)) {

echo "Trouvé !";

}

else

{

echo "non trouvé";

}



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">

<head>

<title>Ok</title>

</head>







<?php echo $titres[ $tit2 ] ?>




:: <?php echo PRESSE; ?> ::


<?php echo $titres[ $arti2 ] ?>







</html>





Le fichier fr-lang :



<?php

$titres array( 'TITREARTICLE_PRESSE'> 'Liste des titres',

'ARTICLEPRESSE' => 'titre1, titre2....',

'TITREARTICLE8_PRESSE' => test1',

'ARTICLE8PRESSE' => 'blablabla',

'TITREARTICLE9_PRESSE' => 'test2',

'ARTICLE9PRESSE' => 'humhum')



?>
0
Jeje_ Messages postés 14 Date d'inscription vendredi 27 février 2004 Statut Membre Dernière intervention 7 octobre 2005
9 août 2005 à 16:13
niquel :) merci beaucoup arno
0
Rejoignez-nous