What is the function of the «??» operator (two questions) in PHP?

Asked

Viewed 3,537 times

9

Analyzing a script PHP at a certain point I came across this line

$valor = $_GET['id'] ?? 1;

What is the interpretation of this code? What does it do?

2 answers

8


  • and this? $value = $_GET['id'] ?? $_POST['id'] ?? 1;

  • @Leocaracciolo tries to get the value of a key called id first in $_GET if there is no attempt at $_POST if it is not found in the latter set as default value 1

  • ball show :)

5

  • was worth the return, but I have no notion in C#

  • 1

    PHP documentation here

  • In PHP, at least Lvis Operator is the ?: and behaves differently from null coalescing.

  • You don’t even have to, so all you needed to know is in the answer.

  • 3

    @Andersoncarloswoss changed there, again PHP being PHP.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.