PHP ise değişken değeri için kontrol deyimi sorun

2 Cevap php

Ben bir özel alan bir şey içine veya eğer girmiş denetler deyimi boş bırakıldı değilse, sadece basit bir PHP yazmaya çalışıyorum.

when it is blank it is meant to not print anything to the page, if something is set in the custom field then it should create a li element with an a tag inside of it.

Burada benim kod şimdiye kadar:

<ul class="externalLinks">
<? $emptycheck = get('linkname',2,1,0);

if (isset($emptycheck)){ ?>
   <li><a href="<? echo get('targethref',2,1,0); ?>"><? echo get('linkname',2,1,0);?></a></li>
<? } else { '' } ?>

<li><a href="<? echo get('PDFdownload'); ?>">Download a PDF of this project</a></li>
</ul>

The custom fields in this case are set by the wordpress admin (through the flutter plugin). The issue I am having is simply that if the custom fields are left blank an empty

<li><a></a></li>

oluşturulur.

('linkname', 2,1,0) almak açıkçası alan içeriği (bu kısım işleri) döndürür.

Herhangi bir fikir çok takdir.

Thanks, Jannis

2 Cevap

Bir değişkenin boş olup sırf isset değil anlamına gelmez ().

Bunu empty () ya da değilse kontrol etmek istiyorum.

$whatever = get('whatever',2,1,0)
if (! empty($whatever)){
//output your stuff
}

Temiz olması için: değişken adı sembol tablosunda varsa isset () sadece size söyleyecektir. Bir değişkenin boş olduğunda boş () true dönecektir.

Belgelere göre:

The following things are considered to be empty:

  • "" (Boş dize)
  • 0 (bir tamsayı olarak 0)
  • "0" (bir dizge olarak 0)
  • NULL
  • YANLIŞ
  • array () (boş bir dizi)
  • var $ var; (Değişken bildirilmiş, ancak bir sınıfta bir değeri olmayan)

Düzenlendi: () boş tür özel ve sadece düzenli bir değişken üzerinde çalışır. Sen boş () ile (örneğin, bir işlevin dönüş değeri) bir ifadeyi test edemez. Bu açıkça manuel sayfasında belgelenmiştir.

Eğer isteyebilirsiniz falsy dönüş değeri varsa, ne olursa olsun $ emptycheck kuruyorsun

if ( $emptycheck ) {
} else {
}

Aksi takdirde her zaman doğru değerlendirecek. Etrafında diğer yolu ise ya bir olumsuzluk operatörü (!) Etrafında mantığı çevirin.