Try to create separate variables for the corresponding positions and assign them the necessary values instead of trying to display the values from the original variables themselves.
I'm still new to PHP, so please point out errors or errors :)
Assuming that the position variables are as follows:
pos1, pos2.<br/> pos3, pos4.<br/> pos5.
then the following may work:
$pos = array ($addressOne, $addressTwo, $city, $province, $country); for ($i=0; i<5; $i++) { if(!$pos[$i]) { $j=$i; while($pos[$j+1]) { $pos[$j] = $pos[$j+1]; //shift the strings one position to the front $j++; } } } echo $pos[0].', '.$pos[1].'.<br/>'. $pos[2].', '.$pos[3].'.<br/>'. $pos[4].'.';
Please note that this will not result in deletion ,
and .
when the corresponding rows are missing. This is easy to do, and I thought it would be superfluous to include this in the answer.
Yours faithfully,
rktcool :)
source share