What are some cool PHP tricks?

Asked by Last Modified  

2 Answers

Learn PHP

Follow 2
Answer

Please enter your answer

1. Create a class for repeated tasks 2. Don't use require, require_once, include, or include_once 3. Make your functions flexible 4. Always correct character encoding for a MySQL connection.
Comments

Senior Web Development Experts, MCA

There are somany cool PHP tricks. Hope below tricks help you a little. 1)Instead of array(), use the shorter syntax:Example:$fruits = ; 2)Null Coalescing Operator (??)(This operator is useful for handling default values. It returns the first operand if it's not null, otherwise, it returns the second...
read more
There are somany cool PHP tricks. Hope below tricks help you a little. 1)Instead of array(), use the shorter [] syntax:Example:$fruits = ['apple', 'banana', 'cherry']; 2)Null Coalescing Operator (??)(This operator is useful for handling default values. It returns the first operand if it's not null, otherwise, it returns the second operand)Example:$username = $_GET['user'] ?? 'guest'; 3) Ternary Operator SimplificationExample:$age = $userAge ?: 18; // If $userAge is falsey, $age will be 18 5)Type Declarations(PHP 7 and later support type declarations for function arguments and return values:)Example:function add(int $a, int $b): int { return $a + $b;} These tricks can help make your PHP code more concise, readable, and efficient. read less
Comments

Related Questions

Can I build iPhone apps using Python?
Yes, you can use PyMob app where apps can be written purely in Python, and the compiler tool flow converts them in native source codes for various platforms. But there are some cons on using PyMob, the...
Sunil
0 0
5
What is the fee for php classess?
Basic + Advanced + WD + MVC, full php developer profile Rs. 12000/- 4 month with practice.
Manjunath
What kind of interview questions are asked for Advanced PHP?
http://phpinterviewquestions.co.in/ http://stackoverflow.com/questions/2118755/questions-every-good-php-developer-should-be-able-to-answer http://www.slideshare.net/vineetkumarsaini/top-100-php-interview-questions-and-answers
Manshi
what is a file handling
File handling is an important part of any web application. You often need to open and process a file for different tasks. PHP has several functions for creating, reading, uploading, and editing files....
Mayank

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

What is M.S.Project ?
MICROSOFT PROJECT contains project work and project groups, schedules and finances.Microsoft Project permits its users to line realistic goals for project groups and customers by making schedules, distributing...

Introduction to Programming Languages
What is a Programming Language? A programming language is a formal computer language or constructed language designed to communicate instructions to a machine, particularly a computer. Programming languages...

A New Way To Learn Web Development.
Hello, My name is Ajay. I work at a small IT company and yes on weekends provides some training and guidance and consultancy to students. Before past 7-8 months, I was just a random student just like so...

Why Choose Magento For E-Commerce Shopping Sites?
There are many CMS and Framework available for Shopping sites then why we choose Magento for store what is the advantage behind them? There are many CMS and Framework available in market who give the...

SQL Union Vs Union ALL
SQL UNION vs UNION ALL Operator Usage UNION: UNION combines the result set of two or more queries into a single result set. UNION removes duplicate records (where all columns in the results are the same). UNION...

Recommended Articles

Information technology consultancy or Information technology consulting is a specialized field in which one can set their focus on providing advisory services to business firms on finding ways to use innovations in information technology to further their business and meet the objectives of the business. Not only does...

Read full article >

Microsoft Excel is an electronic spreadsheet tool which is commonly used for financial and statistical data processing. It has been developed by Microsoft and forms a major component of the widely used Microsoft Office. From individual users to the top IT companies, Excel is used worldwide. Excel is one of the most important...

Read full article >

Business Process outsourcing (BPO) services can be considered as a kind of outsourcing which involves subletting of specific functions associated with any business to a third party service provider. BPO is usually administered as a cost-saving procedure for functions which an organization needs but does not rely upon to...

Read full article >

Whether it was the Internet Era of 90s or the Big Data Era of today, Information Technology (IT) has given birth to several lucrative career options for many. Though there will not be a “significant" increase in demand for IT professionals in 2014 as compared to 2013, a “steady” demand for IT professionals is rest assured...

Read full article >

Looking for PHP Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you