سؤال

I'm new to php and mysql and i'm working on a Zend Projet. I have to display shops with ajax request onthe town. Ajax Part seems to be ok, but i have trouble with the php part :

var_dump($this->Boutiques_Details); 

array (size=565)
  0 => 
    array (size=5)
      'ville' => string 'Fès' (length=4)
      'adresse' => string 'Av Slaoui Resid Des Palmiers Vn Fes' (length=35)
      'quartier' => string 'Ville Nouvelle' (length=14)
      'id' => string '1' (length=1)
      'num_contact_1' => string '212534017800' (length=12)
  1 => 
    array (size=5)
      'ville' => string 'Casablanca' (length=10)
      'adresse' => string 'Angle bd Bir Anzarane et Caid Al Achtar' (length=39)
      'quartier' => string 'Maârif' (length=7)
      'id' => string '2' (length=1)
      'num_contact_1' => string '212529004563' (length=12)
  2 => 
    array (size=5)
      'ville' => string 'Marrakech' (length=9)
      'adresse' => string '2 Angle Bd Zerktouni et Rue Liban' (length=33)
      'quartier' => string 'Gueliz' (length=6)
      'id' => string '3' (length=1)
      'num_contact_1' => string '212529800027' (length=12)
  3 => 
    array (size=5)
      'ville' => string 'Rabat' (length=5)
      'adresse' => string 'N° 1  Angle avenue des nations unies & Av Omar Ibn khattab Agdal' (length=65)
      'quartier' => string 'Agdal' (length=5)
      'id' => string '4' (length=1)
      'num_contact_1' => string '212699529702' (length=12)
  4 => 
    array (size=5)
      'ville' => string 'Casablanca' (length=10)
      'adresse' => string 'Angle Bd hassan II & Bd de Paris ' (length=33)
      'quartier' => string 'Centre ville' (length=12)
      'id' => string '5' (length=1)
      'num_contact_1' => string '212529008573' (length=12)
  5 => 
    array (size=5)
      'ville' => string 'Tanger' (length=6)
      'adresse' => string 'bd pasteur sour meaagazine' (length=26)
      'quartier' => string 'sour meaagazin' (length=14)
      'id' => string '6' (length=1)
      'num_contact_1' => string '212538800322' (length=12)
  6 => 
    array (size=5)
      'ville' => string 'Meknès' (length=7)
      'adresse' => string '6 Av Hassan II - ville nouvelle' (length=31)
      'quartier' => string 'Hemria' (length=6)
      'id' => string '7' (length=1)
      'num_contact_1' => string '212533548651' (length=12)
  7 => 
    array (size=5)
      'ville' => string 'Oujda' (length=5)
      'adresse' => string 'Angle Bd Mohamed V et Bd ahfir, N°1' (length=36)
      'quartier' => string 'Centre Ville' (length=12)
      'id' => string '8' (length=1)
      'num_contact_1' => string '212600001005 ' (length=14)

As you can see it's an array of array.

var_dump($this->ville);

return : string 'Agadir' (length=6)

So i have to do a foreach with a if setting but I * dont know how to do that... Please Help meeee

EDIT : The loop :

foreach( $this->Boutiques_Details as $arr ){
    foreach( $arr as $key => $value ){
        if ($key['ville'] == $this->ville)
        {        
        echo $key . " " . $value;
        }
    }
}

I have no error but the if condition return nothing

هل كانت مفيدة؟

المحلول 2

Don't use propertynames in the foreach. In PHP the foreach syntax is like:

foreach( $this->Boutiques_Details as $arr ){
    foreach( $arr as $key => $value ){
        echo $key . " " . $value;
    }
}

ps. Do not swear. You doesn't look smarter if you do that(a bit immature instead).

نصائح أخرى

You can use only one foreach like this:

foreach( $this->Boutiques_Details as $key => $value){
     if ($value['ville'] == $this->ville) {        
         echo $key . " " . $value;
     }
 }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top