Liron Paryente Liron Paryente - 1 year ago 76
PHP Question

echo array null values

I'm new to PHP and I know this is an easy one but still can't find a solution.

I have an array that holds 4 different images and I want to echo the results
so my HTML looks like this:

<img src="<?php echo $results['image1']?>" >
<img src="<?php echo $results['image2']?>" >
<img src="<?php echo $results['image3']?>" >
<img src="<?php echo $results['image4']?>" >

But what if for example image4 is null? - i don't want to echo the whole
<img src>
tag line

How can i do it?

Answer Source

Here is your work around example.

if(!empty($results['image1'])) echo '<img src="'.$results['image1'].'">';
if(!empty($results['image2'])) echo '<img src="'.$results['image2'].'">';
if(!empty($results['image3'])) echo '<img src="'.$results['image3'].'">';
if(!empty($results['image4'])) echo '<img src="'.$results['image4'].'">';

try this code may it helps you. here i have check first if result not empty.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download