All Shorthand code of PHP

PHP is a easy language to learn and having some short hand codes which can make your code less and more beautiful and easy to understand . today i am going to discuss some method by which you can decrease your code lines with same effect .

Print statement : If you want to just echo a php variable inside the html code or anywhere the most people use

but alternatively we can print the same variable with

the following line will produce a same result and taking less time to write . It can help you to write quick code .

minimize Braces : Sometime you don’t need to add braces if your statement has only one directive . It can save a lot of time . i.e

as we can see the following code has only one directive so we can write the same code as given below

Ternary operator : The short code i love to use always . It saves a lot of time and always easy to ready inside the html tag .

with Ternary operator the same code can be written as

Easy to write and can be written in just one line .

with Ternary operator we can set a value in variable , we can print values , we can return values and many more . Here is a example

Alternative syntext : Php offers some alternative syntax for some of control statements . like for , if, while , in this the opening braces replaced with colon(:) and closing braces with endif; , endforeach; , endfor; , endswitch respectively. this can be very useful if you are using html code inside the php code .I.e

same for other control statement this can be use.

Incremental Operators: In loops like for loop, foreach loop and while loop we need to increment a counter variable so that we can get the no for each cycle . and we need to increment on each cycle

Array shorthand PHP 5.4 introduced an array shorthand