Похожие чаты

Hello! How can I type hint the return types in

PHP for the following RECURSIVE function?


function display(array $input)
{
foreach ($input as $key => $value) {
echo $key;

if (is_array($value)) {
/** Call the same function again */
return display($value);
}

echo $value;
}
}

The following works but I get 500 Internal error in the console of the browser


function display(array $input) : mixed


Is there a way I can use UNION Types over here? If yes then which are those

9 ответов

21 просмотр

is mixed a return type? i think it should be void or separated by a | if there is more than one return type

Your function doesn't actually return anything, just echoes

Flying-Dragon Автор вопроса
Richard | If you DM for support you PAY
is mixed a return type? i think it should be void ...

I think this was like a mind game for me. With union I can use pipe ( | ) operator I can use multiple

Flying-Dragon Автор вопроса
Furison, Code Monkey
Your function doesn't actually return anything, ju...

Yup it prints the data. Also it calls the same function (RECURSION) in one of the condition So I cannot just use void as void means nothing. Also if I use void I cant use (union with other data types) any other data types with it

Flying Dragon
screenshot I think this was like a mind game for me. With uni...

Didn't know about the mixed return type, right now mostly working on php 7.1 supported features as most servers haven't upgraded to php 8.0 yet

Flying Dragon
Yup it prints the data. Also it calls the same fun...

Sorry it was late when I read this. Looking at this again, when you recursively call the function you return the result of it, but it doesn't actually return anything. Instead of trying to return the result of recursively calling the function, you should just call it, ie use display($value); instead of return display ($value);

Flying-Dragon Автор вопроса
Richard | If you DM for support you PAY
Didn't know about the mixed return type, right now...

You can upgrade the PHP 7.4 to PHP 8.x in servers with the help of PPA Ondrej Repository. PHP 8.0 is really awesome in terms of performance. They even state that they have 2 JIT compilers as per the feature released for 8.0

Flying-Dragon Автор вопроса
Furison, Code Monkey
Sorry it was late when I read this. Looking at thi...

You cannot omit the return keyword. If you could run the following example you will understand it. $array = [ 'a' => 'b', 'c' => 'd', 'e' => ['f' => ['g' => ['h' => 'i']]] ]; display($array);

Flying Dragon
You can upgrade the PHP 7.4 to PHP 8.x in servers ...

What i mean is making cross php applications, where you leave the user to setup by themselves, for example code canyon projects where you do not know the environment a user will run your app in

Похожие вопросы

Обсуждают сегодня

Hey everyone! I won’t focus too much on what this person said (it’s clear they don’t understand the scope of what TF and TELOSX are achieving), but I’ll put it simply for thos...
Ana Ojeda
3
what do you guy think about the current performance of $FTM compare to the rest of the market?
💀zeThrouzz🦞
12
Hi did any of you experience a file error when download hex file for Windows?
Valya
17
Ready for some fun AND a chance to win TKO Tokens? Join us for exciting minigames in our Telegram group! 🕒 Don’t miss out—games start on today 25 October 2024, at 8 PM! Ge...
Milkyway | Tokocrypto
255
как правильно удалить сддм? прописал в etc/portage.use/plasma-meta -sddm , но при обновлении юзов мне предлагает поставить lightdm (ещё лучше 😡), добавил туда - display-manage...
REDis
25
Всем привет! Имеется функция: function IsValidChar(ch: UTF8Char): Boolean; var i: Integer; ValidChars: AnsiString; begin ValidChars := 'abcdefghijklmnopqrstuvwxyzABCDE...
Евгений
44
Коллеги, я тут для личных нужд пошел ставить MQTT сервер, пощупал mosquitto, но ужаснулся отсутствию такой банальности, как HTTP API для посмотреть список топиков. А тут что,...
Maksim Lapshin
14
Please I want to ask if my stake is 24% complete, what penalty will I pay if I end the stake?
Crypto Advocate
12
Also, scrolling at the history here, I see there was alot of hate towards kaspa.. is it still the case after they proved the history of the chain?
Gad Levy | AnyLog
11
Could the new Norse labs apps have just been called "VPN" instead of DVPN?
HDGVII
14
Карта сайта