I have a php code like this.
<?php
$books = get_group('books');
if($books){
$booksfilter = "";
foreach($books as $book){
$booksfilter .= "<ul class=\"books\">";
$booksfilter .= "<li><a href='".$book['books_image'][1]."' >image</a></li>";
$booksfilter .= "<li>".$book['books_image_title'][1]."</li>";
$booksfilter .= "<li>".$book['books_image_description'][1]."</li>";
$booksfilter .= "</ul>";
}
echo $booksfilter;
} ?>
The code working fine. My problem is I have some problem while giveing css padding for li elements. It creates empty space when thearray has no value. So can anyone tell me how to check whether the value exists or not.
I mean i want something like this
if value exists ($book['books_image_description'][1])
{
$booksfilter .= "<li>".$book['books_image_description'][1]."</li>";
}
Can anyone help me? Thanks
If this is a string and in most of the other cases, casting to boolean will do the job.
booleancast of an empy string is equal tofalseif key does’n exist it will be a null pointer, which casted to boolean is also
false.so you have 2 at the price of a 1 … won’t insert the
liif key doesn’t exist and if exist and its value is an empty string – which I think is you idea.