<?php echo isset($areas['footer']) ? $areas['footer'] : null; ?>
Bu geliştirmek için herhangi bir şekilde?
Eğer yankılanan ve yanlış durumda herhangi bir etkisi yoktur null hangi olacağını unutmayın. Yerine 'empty' veya ' ' veya 'not found' gibi diyebiliriz. Diğer alternatif dönüş değerini almak için isset:
$return = isset($areas['footer']) ? $areas['footer'] : null;
if ($return)
{
// $return contains footer info
}
else
{
// footer was not set :(
}
echo $areas['footer'];
Basit ve orijinal çizgi tam olarak aynı etkiye sahiptir.
Edit in reply to Felix This gives a notice, but unless you're supposed to turn this in as ultra-perfect homework, it doesn't really matter. You can either fill your code with isset calls or ignore small stuff like this. I'd worry about it if I was working in say... Java, but pragmatically nobody is going to care if PHP code that works produces notices.