Tips in golfing using PHP
This is a list of golfing tips for the language known as Philippine Peso PHP. If you have a tip, add it in!
Whitespace can be removed in b …
3y ago
Anything that's outside the sc …
3y ago
Use `Used on Reverse an ASCII …
3y ago
Remove `?>` You can save 2 …
3y ago
Set arrays without `array()` …
3y ago
5 answers
You are accessing this answer with a direct link, so it's being shown above all other answers regardless of its score. You can return to the normal view.
Anything that's outside the script is echoed
This probably has to deal with the fact that PHP is a script commonly used on HTML, and anything that is written on the HTML document--not inside the script--is outputted.
Used on "Hello, World!".
0 comment threads
Whitespace can be removed in between keywords and variables
You can easily remove the whitespace that's in-between a keyword (return
or a function that doesn't need parentheses) and a variable (either starting with $
for the variable's name or "
if the variable to deal with is a string):
<?php $x=9+10;echo"Hello!\n";echo$x;
0 comment threads
Remove ?>
You can save 2 bytes by removing the syntax that ends the PHP script when you don't need it. The program will still work.
<?php echo"Hello!";
0 comment threads
Set arrays without array()
In a few occasions, setting an array using array()
can be a bit costly. Thankfully, you can assign an array like how to assign a Python list.
<?php $a=["Hello","MarkFuncs","Golfing"];print_r($a);
0 comment threads