A
A
Anastasia2021-07-01 09:58:49
PHP
Anastasia, 2021-07-01 09:58:49

How to assign an element of an array to a variable, which may not be?

Hello. Now I do like this:

if (isset($tg['message']['text'])) {
  $msg = $tg['message']['text'];
}

but I would like to know if there are more elegant entries in PHP8?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2021-07-01
@nastya97core

$msg = $tg['message']['text'] ?? null;

S
StApostol, 2021-07-01
@StApostol

$msg = $tg['message']['text'] ?? null;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question