Here are some examples of language constructs:
echo() include() require() print() isset() die()Language constructs cannot be added to PHP environment through any plugins or libraries. They may or may not return any value, although most of them do not. Also, some of them do not need to use parentheses.Below are examples of using the language construct in PHP:
Example 1:
print
(
’ Monday ’
);
print
’Tuesday’
;
$str
=
’Wednesday’
;
echo
$str
;
?>
Exit:Monday Tuesday Wednesday
Example 2:
/ * PHP program to use unset
function * /
$arr
=
array
(
"1"
= >
"Amit"
,
"2"
= >
"Rajeev"
,
"3"
= >
"Mohit"
,
"4"
= >
"Manoj"
);
// Use an undefined function for
// unset element
unset (
$arr
[
"2"
]);
// Show array element
print_r (
$arr
);
?>
Exit:Array ([ 1] = > Amit [3] = > Mohit [4] = > Manoj)
On the other hand, built-in functions- they are blocks of code that are written in such a way that they can be used over and over again for a specific task. They are already included in the PHP installation package. It is these built-in features that make PHP an efficient scripting language.
Some common built-in functions used in PHP:json_encode() mail() explode() rand() curl_init()
Built-in functions are comparatively slower than their language analogs. They have better code organization. They usually take input arguments and always return a value. Built-in functions usually consist of date, number, and string functions.Below are examples to illustrate the use of the built-in function in PHP:
Example 1:
/ * PHP date functions * /
echo
"Date and time is -"
;
print
date
(
"j FY, gia"
, time());
?>
Exit:Date and time is - 26 February 2019, 12.22.pm
Example 2:
/ * String functions in PHP * /
$MyStr
=
"GeeksForGeeks"
;
echo
substr
(
"GeeksForGeeks"
, 5, 3).
""
;
echo
trim ( " GeeksForGeeks "
).
""
;
echo
str_replace
(
"Geeks"
,
" Code "
,
" GeeksForGeeks "
);
?>
Exit:For GeeksForGeeks CodeForCode