DEV Community

Cover image for PHP crash course : Conditionals, Loops and Functions

PHP crash course : Conditionals, Loops and Functions

Eric The Coder on January 23, 2022

Today you will learn conditionals, loops and functions création in PHP. This PHP crash course is free and will be posted here on dev.to. I'll be r...
Collapse
 
peter279k profile image
peter279k •

These code snippets are not correct:

x$ = 10;

$sum = function ($a, $b) use $x (
    return $x + $a + $b;
);

echo $sum(10, 15);
// 35
Enter fullscreen mode Exit fullscreen mode

It should change into:

$x = 10;

$sum = function ($a, $b) use $x (
    return $x + $a + $b;
);

echo $sum(10, 15);
// 35
Enter fullscreen mode Exit fullscreen mode
Collapse
 
aswierc profile image
Artur Świerc •

a mix php with html is not a good way to show a modern php :) but I left heart for making php more popular these times :)

Collapse
 
ivanjrmc profile image
Ivan Jeremic •

Php started as templating language so totally ok.

Collapse
 
aswierc profile image
Artur Świerc •

yep, that was, but it's not an example of modern PHP nowadays, that was what I meant

Thread Thread
 
tobisgd profile image
TobiSGD •

You don't work with frameworks like Magento 2, I assume? Using PHP as templating language is quite common and not in any way not modern.

Thread Thread
 
ivanjrmc profile image
Ivan Jeremic •

I agree templating is can be part in any language especially in PHP

Collapse
 
ysftmd profile image
YSF-TMD •

when u say modern php what do u mean , native php or frameWorks ?

Collapse
 
ramlev profile image
Hasse R. Hansen •

the if statement, checking if a string is valid, should always be === since its always same type

Collapse
 
ericchapman profile image
Eric The Coder •

Good point I made the change. Thanks for your comment.

Collapse
 
peter279k profile image
peter279k •

The $ position I think it's not correct: Shipping 9.95$.

I think it should be Shipping $9.95.