What is type casting and type juggling in php?

0 votes
How type casting and type juggling can be useful in php and what the difference between them? Can anyone explain me out with any sample code of it??

Thank you!
Mar 27 in PHP by kartik
• 10,990 points
48 views

1 answer to this question.

0 votes

Hey,

The way by which PHP can assign a particular data type for any variable is called typecasting. The required type of variable is mentioned in the parenthesis before the variable.

Sample code:

$str = "10"; // $str is now string

$bool = (boolean) $str; // $bool is now boolean

PHP does not support data type for variable declaration. The type of the variable is changed automatically based on the assigned value and it is called type juggling.

Sample code:

$val = 5; // $val is now number

$val = "500" //$val is now string

Thank You!

answered Mar 27 by Niroj
• 22,110 points

Related Questions In PHP

0 votes
0 answers

What are the differences in die() and exit() in PHP?

I think both have the same functionality, ...READ MORE

Apr 8 in PHP by kartik
• 10,990 points
23 views
0 votes
1 answer

What is the use of the @ symbol in PHP?

Hello @kartik, The @ symbol is the error control operator ("silence" or "shut-up" ...READ MORE

answered Apr 8 in PHP by Niroj
• 22,110 points
39 views
0 votes
1 answer

What is a Cookie? How to create Cookies With PHP?

A cookie is often used to identify ...READ MORE

answered Feb 13 in PHP by Niroj
• 22,110 points
106 views
0 votes
1 answer

What is Php json?

Hii @kartik, JSON stands for JavaScript Object Notation, ...READ MORE

answered Feb 14 in PHP by Niroj
• 22,110 points
63 views
0 votes
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 22,110 points
417 views
0 votes
1 answer

How can we create a session in PHP?

Hello @kartik, session_start() function is used in PHP to ...READ MORE

answered Mar 27 in PHP by Niroj
• 22,110 points
33 views
0 votes
1 answer

How to clone a JavaScript object?

Hello, You can clone an object and remove ...READ MORE

answered Apr 2 in Java-Script by Niroj
• 22,110 points
15 views
0 votes
1 answer

what is the $(document).ready equivalent without jQuery?

Hello @kartik, There are three options: If script is the last ...READ MORE

answered Apr 2 in Java-Script by Niroj
• 22,110 points
79 views
0 votes
1 answer

What is meant by passing the variable by value and reference in PHP?

Hello, When the variable is passed as value ...READ MORE

answered Mar 27 in PHP by Niroj
• 22,110 points
36 views
0 votes
1 answer

What is the use of $_REQUEST variable in php?

Hii @kartik, The $_REQUEST variable is used to read the ...READ MORE

answered Mar 27 in PHP by Niroj
• 22,110 points
49 views