Похожие чаты

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 ответов

22 просмотра

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

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта