0

Is is possible to use implode directly in Heredoc ?

Here is a sample GraphQL query I'd like to generate:

query {
    forms(siret: "whatever", status: [STATUS_1, STATUS_2, STATUS_3]) {
        id
        status
    }
}

Here what I came up to, which works great:

$siret = "whatever";
$status = array("STATUS_1", "STATUS_2", "STATUS_3");
$inline_status = implode(',', $status);

$query = <<<JSON
query {
    forms(siret: "{$siret}", status: [{$inline_status}]) {
        id
        status
    }
}
JSON;

Is there a way to achieve the inlining directly in the query ? Something like so (that obviously doesn't work):

$query = <<<JSON
query {
    forms(siret: "{$siret}", status: [{$implode(',', $status)}]) {
        id
        status
    }
}
JSON;
pistou
  • 2,799
  • 5
  • 33
  • 60
  • FYI: That is not actually JSON. So a different identifier for your heredoc might be in order :-) – CBroe Feb 08 '23 at 09:36

0 Answers0