Follow me!: Follow @EricTheCoder_
Here is my cheat sheet I created along my learning journey. If you have any recommendations (addition/subtract...
For further actions, you may consider blocking this person and/or reporting abuse
Nice one Eric! You can also add this trick to make numbers even more readable
Oh didn't know about that. Thanks 👍
Oh like in the JS env ! Thanks for this trick @khalyomede ! 😊
Invokable classes:
class A {
public function __invoke() {
print_r('Hello world!);
}
}
$a = new A();
($a)(); // 'Hello World'
array_reduce:
$total = array_reduce(
$arr,
function($ac, $item) { return $ac + $item; },
0
);
Destructuring arrays:
$arr = [
[1, 'name1'],
[2, 'name2'],
];
[$firstEl, $secondEl] = $arr ; // firstEl = [1, 'name1'], secondEl = [2, 'name2']
[$id, $name] = $firstEl; // $id = 1 | $name = name1
Destructuring in a loop:
`foreach ($arr as [$id, $name]) {
}`
Thank you for the very interesting article, however I have two comments while going through the article:
the first in Conditionals: switch ($ color) there are two "red" cases
the second in array: // Array declaration can contain any types
$ example = ['Mike', 50.2, true, ['10', '20'];
a "]" is missing at the end
Done. Thanks
Love to see all php8 stuff 🤩
Great cheat sheet.
Try to use <?php in place of <? as the tag isn't enabled in recommended production or development environments:
; short_open_tag
; Default Value: On
; Development Value: Off
; Production Value: Off
When you use it and it's not enabled, either your file will error out, or your source code will leak to your output.
Try var_export, it's similar to var_dump and print_r. It outputs content in php syntax, similar to how json_encode will return content in json syntax.
Nice cheatsheet. Very helpful.
FYI, classes don't use sTuDLy cApS, they use PascalCase aka UpperCamelCase (because camel case can mean either camelCase or CamelCase, making the word completely useless... the term lowerCamelCase should be used to avoid confusion).
nice job Eric
wow, i must say this is quite comprehensive.
I think you could add Superglobals as well
thanks :)
Really Nice Eric.
Have you thought in making a gist of it?
thanks
Thank you! As a PHP developer, I see myself coming back to this over the next couple of months.
Very helfull, thank very much for this wonderful articles
Very nice cheat sheet Eric ! You can also add the tag for others popular PHP frameworks like Symfony (not only Laravel) to increase your visibility 😉