2016-04-14 10 views
-2

İki değerin karşılaştırıldığı php kodu buradadır. Kurs değerleri, veritabanından gelen denetleyiciden geçirdiğim değerlerdir ve prev_course daha önce seçilen değere sahiptir. Karşılaştırma bir seferde aynı olmasına rağmen, kodun her zaman başka bir bölümünü gösteriyor. Eğer 3 çıkış aynı GRE ve GRE ama hala gösteriliyor görebileceğiniz gibi değil aynı, değerlerin aynı olmasına rağmen karşılaştırmaya eşittir

kodun çıktısı burada bu

not same 
prev course= GRE and from db=IELTS 
not same 
prev course= GRE and from db=TOFELS 
not same 
prev course= GRE and from db=GRE 

gibi geliyor Ben karşılaştırma için php kodudur denenmiş hem == ve ===

<?php foreach($instructor_course as $courses):?> 
    <?php if($courses['name']===$prev_course):?> 
    <?php echo 'same<br/>';?><?php echo "prev course=$prev_course"." and from db=".$courses['name'] ."<br/>";?> 

    <?php else: ?> 
<?php echo 'not same <br/>';?><?php echo "prev course=$prev_course"." and from db=".$courses['name'] ."<br/>";?> 
<?php endif;?> 
<?php endforeach;?> 
+0

@PaulCrovella Yorum yazabilmek için cevap yazabilir. – Asaph

cevap

2

bu deneyin:

foreach($instructor_course as $courses) { 
    if($courses['name'] === trim($prev_course)) { 
     echo 'same<br/>'; 
     echo "prev course=$prev_course and from db=$courses['name']<br/>"; 
    } else { 
     echo 'not same <br/>'; 
     echo "prev course=$prev_course and from db=$courses['name'] <br/>"; 
    } 
}