I have read many things around the use of isset()
and empty
, but am not able to find the answer I am looking for.
Basically this: A user fills in some html inputs on post, which calls a php script. Prior to calling a separate web service to look up an address, I need to create a string with all of the address elements that have been populated. Where an input field has not been populated I want to exclude it from the list.
In short:
- Check posted
$vars
1 to 10 to see if they contain a value. - For each one that has no value, remove it from the string. Where a value is present, add it to the string.
I have tried using empty
, !empty
, isset
and still haven't worked it out.
Sample code:
<?php
if
(empty($Lot_no))
{ $Lot_no = $v1;
}
if (empty($Flat_unit_no))
{$Flat_unit_no = $v2;
}
$str= $v1. $v2;
?>