<?php
function wrapWithUnion
(array $params) {
return "'{$params[1]}'";
}
return "ST_Union({$params[0]},'{$params[1]}')";
}
$arr = array("eee","fff","ggg","hhh");
$result = null;
foreach ($arr as $val) {
$result = wrapWithUnion
(array($result, $val)); }
PD9waHAKCmZ1bmN0aW9uIHdyYXBXaXRoVW5pb24oYXJyYXkgJHBhcmFtcykKewogICAgaWYgKGlzX251bGwoJHBhcmFtc1swXSkpIHsKICAgICAgICByZXR1cm4gIid7JHBhcmFtc1sxXX0nIjsKICAgIH0KCiAgICByZXR1cm4gIlNUX1VuaW9uKHskcGFyYW1zWzBdfSwneyRwYXJhbXNbMV19JykiOwp9CgokYXJyID0gYXJyYXkoImVlZSIsImZmZiIsImdnZyIsImhoaCIpOwoKJHJlc3VsdCA9IG51bGw7Cgpmb3JlYWNoICgkYXJyIGFzICR2YWwpIHsKICAgICRyZXN1bHQgPSB3cmFwV2l0aFVuaW9uKGFycmF5KCRyZXN1bHQsICR2YWwpKTsKfQoKdmFyX2R1bXAoJHJlc3VsdCk7