Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs

Dashboard
Notifications
Mark all as read
Q&A

Tips in golfing using PHP

+1
−0

This is a list of golfing tips for the language known as Philippine Peso PHP. If you have a tip, add it in!

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

5 answers

+1
−0

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!";

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+1
−0

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!".

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+1
−0

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;

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+1
−0

Use <?=

It's basically the same as <?php echo.

Used on Reverse an ASCII string.

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+0
−0

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);

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »

This community is part of the Codidact network. We have other communities too — take a look!

You can also join us in chat!

Want to advertise this community? Use our templates!