Blank response in XML WebService


I am trying to create a webservice that would output either in JSON or XML format depending on the user’s choice.

I problem comes when I am sending a boolean datatype to the user in XML format.

When the datatype is true, it sends the following:

<?xml version='1.0' encoding='UTF-8'?> 

But when the datatype is false, it sends blank value under <result>:

<?xml version='1.0' encoding='UTF-8'?> 

But it works well when the format is JSON:

In case of true:


In case of false:


Here is my code that generates XML or JSON:

			$mode = 'XML'; //Change to XML or JSON
            $return = array(
                'result' => true
            if('XML' == $mode){
		        print "<?xml version='1.0' encoding='UTF-8'?>\
		        print "<output>\
		        foreach ($return as $element => $content) {
		           print "<$element>";
		           print $content;
		           print "</$element>\
		        print "</output>";
				echo(json_encode($return) );die;            



Can someone please help me understand this mystery?


Let’s do a little exercise: Please run the following code and have a look at what happens:

echo true;
echo false;