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, 2020 in PHP by kartik
• 37,510 points
4,274 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, 2020 by Niroj
• 82,820 points

Related Questions In PHP

0 votes
0 answers

What is the difference between Sessions and Cookies in PHP?

What is the distinction between Sessions and Cookies ...READ MORE

Jun 13, 2022 in PHP by narikkadan
• 50,840 points
100 views
0 votes
0 answers

What is the difference between ' and " in PHP?

What is the difference between ' and ...READ MORE

Jun 17, 2022 in PHP by narikkadan
• 50,840 points
93 views
0 votes
0 answers

What is the difference between POST and GET in HTML/PHP

I don't seem to understand what GET ...READ MORE

Jun 17, 2022 in PHP by narikkadan
• 50,840 points
86 views
0 votes
0 answers

What is function overloading and overriding in php?

What is function overloading and function overriding? ...READ MORE

Jun 18, 2022 in PHP by narikkadan
• 50,840 points
204 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

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

answered Mar 18, 2020 in Laravel by Niroj
• 82,820 points
17,332 views
0 votes
2 answers

How can we create a session in PHP?

Hello, niroj. Here is my idea session_start(); $_SESSION['USERNAME'] ...READ MORE

answered Dec 7, 2020 in PHP by Famous
• 140 points
559 views
0 votes
1 answer

How to clone a JavaScript object?

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

answered Apr 2, 2020 in Java-Script by Niroj
• 82,820 points
321 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, 2020 in Java-Script by Niroj
• 82,820 points
15,684 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, 2020 in PHP by Niroj
• 82,820 points
1,958 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, 2020 in PHP by Niroj
• 82,820 points
1,358 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP