Convert node ID from string to integer Retrieve a node based on condition:
$query = \Drupal::entityQuery('node')
-&gt;condition('type', 'my_content_type')
-&gt;condition('title', 'my node title');
$nid = $query-&gt;execute();

The result of $nid is the correct node ID but the format is a string, (es: &quot;123&quot;)
When I want to load the node by its ID, I write:
$node_id = Node::load($nid);

Doing this, the result I get is NULL because the variable $nid is holding a string (not integer).
If I write the code like this:
$node_id = Node::load(123);

I get the node loaded.
How can I convert the variable string ($nid) as an integer ?
I tried:
$nid_int = (int) $nid;
$node_id = Node::load($nid_int);

also I tried:
$nid_int = intval($nid);
$node_id = Node::load($nid_int);

But I alwas get result NULL
Thanks for your help
the $query-&gt;execute(); return an array of key/value like [KEY =&gt; nid1]:
if you are sure you have only one node with that tittle you should get the first element of the array it's your nid try with:
 $query = \Drupal::entityQuery('node')
  -&gt;condition('type', 'my_content_type')
  -&gt;condition('title', 'my node title');
$nids = $query-&gt;execute();
// Get the nid in the array.
$nid = reset($nids);
$node = Node::load($nid);