-1

I'm doing some tests in PHP to make an api and use it from nodejs,

i did something like :

<?php

function test () {
    $var = 'School';

    return json_encode($var);
}

echo test();

?>

it works great,

so my question is : do I need to display my response (with echo) ?

I get my results in nodejs. if I don't display my data with echo I receive an empty result.

Thanks for you help.

smiley
  • 15

1 Answers1

3

Yes. You may also want to send headers what sort of data you're returning (for example, application/json Content-Type) using header function (before echoing anything).

Giedrius
  • 1,370
  • 3
  • 14
  • 37