Type casting and type juggling In Hindi

Type casting and type juggling In Hindi

पीएचपी वेब डेवलपमेंट स्क्रिप्ट में टाइप कास्टिंग और टाइप जॉगलिंग एक फंडामेंटल प्रोग्रामिंग कॉसेप्ट हैं, पीएचपी में टाइप कास्टिंग और टाइप जॉगलिंग पीएचपी डेवलपमेंट एनवायरनमेंट में मल्टीप्ल प्रोग्रामिंग डाटा टाइप्स प्रोग्राम्स डाटा वेरिएबल्स को कन्वर्ट मैनेज और कण्ट्रोल करने में हेल्प करते हैं।

Type casting and type juggling In Hindi

So, let’s explore the concepts of type casting and type juggling in PHP web development.

Type Juggling in PHP.

टाइप जॉगलिंग कांसेप्ट पीएचपी वेब डेवलपमेंट में उस फीचर्स को इंडीकेट करता है, जहा मल्टीप्ल प्रोग्राम डाटा ऑपरेशन को अप्लाई करने पर मल्टीप्ल प्रोग्राम डेटा टाइप्स के बीच आटोमेटिक आर्डर में कन्वर्ट हो जाती है। याद रहे, पीएचपी वेब डेवलपमेंट लैंग्वेज एक शिथिल टाइप की जाने वाली प्रोग्रामिंग लैंग्वेज है, इसका मतलब है कि पीएचपी वेब डेवलपमेंट में प्रोग्रामर को किसी वेरिएबल के डाटा टाइप को क्लियर आर्डर स्ट्रक्चर में डिक्लेअर करने की जरूरत नही होती है। जहा पीएचपी वेब डेवलपमेंट कोर एनवायरनमेंट में प्रोग्रामर को डिक्लेअर किसी प्रोग्राम वेरिएबल को आटोमेटिक आर्डर में करंट डाटा टाइप से किसी अन्य दूसरे डाटा टाइप में इमीडियेट कन्वर्ट कर देता है।

Example of type juggling in PHP web development.

पीएचपी वेब डेवलपमेंट में मेथेमेटिकल प्रोग्राम में पीएचपी वेब डेवलपमेंट एनवायरनमेंट जरूरत पड़ने पर स्ट्रिंग्स डाटा टाइप को आटोमेटिक आर्डर में न्यूमेरिक डाटा टाइप में कन्वर्ट कर देता है.

<?php

    $integer = “1”;     // here integer declare as String data type

    $output = $integer + 2;  // here String “1” is automatically converted by php to a integer data type

    echo $output;  // Result – 3

?>

In this type juggling example.

यहाँ स्ट्रिंग डाटा टाइप “1” को 2 में ऐड करने पर यह आटोमेटिक आर्डर में एक इन्टिजर डाटा टाइप में कन्वर्ट कर देता है।

इसी तरह पीएचपी वेब डेवलपमेंट में पीएचपी जरूरत पर अन्य डाटा टाइप को एक दूसरे में आटोमेटिक आर्डर में कन्वर्ट कर सकता है.

<?php

    $text = “1.7”;     // text data type declare as String

    $output = $text + 4.4; // here String “1.7” is automatically converted to float data type

    echo $output;  // output – 6.1

?>

When does PHP use type juggling in web development?

String to Numeric Conversion – यदि किसी पीएचपी वेब डेवलपमेंट में स्ट्रिंग में कोई न्यूमेरिक वैल्यू है, तो पीएचपी डेवलपमेंट एनवायरनमेंट में इसे मेथेमेटिकल ऑपरेशन के लिए स्ट्रिंग को न्यूमेरिक डाटा टाइप में कन्वर्ट कर देगा।

<?php

$int = “4”;

$total = $int + 6; // here PHP will convert $int data type from string to integer type

echo $total;  // Result – 10

?>

Numeric to String Conversion – जब किसी पीएचपी वेब डेवलपमेंट में न्यूमेरिक वैल्यू को स्ट्रिंग डाटा टाइप में ऐड किया जाता है, तो पीएचपी उस न्यूमेरिक वैल्यू को स्ट्रिंग डाटा टाइप में कन्वर्ट कर देता है।

<?php

$integer = 7;

$string = “Here is the integer value is – ” . $integer;  // here php use method to Concatenation: $integer is cast to string data type

echo $string;  // Result – Here is the integer value – 7

?>

Boolean to Number Conversion – पीएचपी डेवलपमेंट में मैथमेटिकल ऑपरेशन में बूलियन लॉजिक को अप्लाई करने पर यह फाल्स आउटपुट को 0 में और ट्रू आउटपुट को 1 न्यूमेरिक वैल्यू में कन्वर्ट कर देता है।

<?php

$bool_value = true;

    echo $bool_value + 2;  // Result – 3 here true Boolean output is act as 1 and add in bool_value variable

?>

Array to String Conversion – पीएचपी डेवलपमेंट में यदि प्रोग्रामर किसी ऐरे डाटा टाइप को स्ट्रिंग डाटा टाइप के आर्डर में ट्रीट करते हैं, तो पीएचपी डेवलपमेंट सामान्यता इसे एक एम्प्टी स्ट्रिंग में कन्वर्ट कर देगा या इसे इको जैसे रेफ़्रेन्स में प्रीव्यू करने पर यह एक एरर को डिस्प्ले करता है।

Type Casting in PHP.

पीएचपी डेवलपमेंट में टाइप कास्टिंग एक डेटा टाइप को किसी अन्य दूसरे डेटा टाइप  में कन्वर्शन करता है। इसमें पीएचपी टाइप कास्टिंग टाइप जॉगलिंग के विपरीत, जहाँ पीएचपी ऑटोमेटिकली आर्डर में इसे कन्वर्ट करता है, वही यहाँ प्रोग्रामर टाइप कास्टिंग में पीएचपी को क्लियर इंडीकेट करना होगा कि मौजूदा प्रोग्राम सोर्स कोड में  किसी डिक्लेअर वेरिएबल का डाटा टाइप कन्वर्ट करना चाहते हैं।

There are two methods of type casting in PHP development.

First – implicit type casting automatic type casting method.

पीएचपी डेवलपमेंट में जरूरत होने पर पीएचपी कुछ डाटा टाइप वेरिएबल को आटोमेटिक आर्डर में कास्ट करता है। जैसे, मल्टीप्ल डाटा टाइप के वेरिएबल को जैसे, स्ट्रिंग और इन्टिजर डाटा टाइप के साथ मेथेमेटिकल ऑपरेशन करते समय, पीएचपी आटोमेटिक आर्डर में स्ट्रिंग डाटा टाइप को एक नंबर डाटा टाइप में कन्वर्ट कर  देता है।

<?php

    $text = “2”;   // here text String variable declare

    $integer = 3;     // here Integer data type declare

    $total = $text + $integer;  // here PHP automatically casts $str data type to an integer data type

    echo $total;  // Result – 5

?>

Second – Explicit Type Casting Manual type casting.

पीएचपी डेवलपमेंट में डिक्लेअर प्रोग्राम वेरिएबल्स को मल्टीप्ल डाटा टाइप्स में क्लियर आर्डर में कास्ट कर सकते हैं।

यहाँ प्रोग्रामर इसे निम्न में से किसी एक तरीके से अप्लाई कर सकते हैं, जिसे

डाटा टाइप कास्टिंग, जो की क्लियर डाटा टाइप कास्टिंग कहा जाता है,

जिसमे किसी डाटा टाइप वैल्यू को क्लियर आर्डर में कन्वर्ट करने के लिए int, float, string, आदि का डाटा टाइप का यूज़ कर सकते है।

Casting to an integer in PHP development.

<?php

    $p = “6.89”;   // here String data type declare

    $int_p = (int) $p;  // here it Explicit casting to integer data type

    echo $int_p;  // Result – 6

?>

Casting to a float in PHP development.

<?php

    $p = “6.89”;   // here p variable declare as String

    $float_p = (float) $p;  // here Explicit casting to float data type

    echo $float_p;  // Result – 6.89

?>

Casting to string in PHP development.

<?php

    $p = 4562;    // here p declare as Integer data type

    $string_p = (string) $p;  // here it Explicit casting to string data type

    echo $string_p;  // Result – “4562”

?>

Casting to boolean in PHP development.

<?php

    $p = 1;    // here Integer 1 is indicated as true in PHP

    $bool_value = (bool) $p;  // here Explicit casting to boolean variable

    var_dump($bool_value);  // Result – bool(true)

?>

settype() function use in PHP development.

पीएचपी डेवलपमेंट में किसी वेरिएबल के डाटा टाइप को बदलने के लिए settype() फ़ंक्शन को भी यूज़ कर सकते है.

<?php

    $p = “576.32”;  // here String data type declare

    settype($p, “int”);  // here it Casts $p variable to an integer data type

    echo $p;  // Result – 576

?>

Type casting and juggling examples in PHP development.

<?php

    // here we use Type Juggling in php to automatic type conversion method

    $p = “60”;  // p declare as String

    $total = $p + 40;  // PHP converts the string to an integer data type for addition

    echo $total;  // Result – 100

    echo “\n”;

    // here we use Explicit Type Casting method

    $str = “7.89”;  // str declare as String data type

    $int_value = (int) $str;  // here we Manually cast to integer data type

    echo $int_value;  // Result – 7

    echo “\n”;

    // here we use Casting using settype() function method

    $q = “89.43”;  // here we declare String data type

    settype($q, “float”);  // here we Casts $q variable to as float data type

    echo $q;  // Result – 89.43

    echo “\n”;

    // here we use Type Juggling with Boolean data type

    $is_value = “True”;  // here we declare true as String data type

    $bool_value = (bool) $is_value;  // here we Cast string to boolean data type

    echo $bool_value ? ‘True’ : ‘False’;  // Result – True

    echo “\n”;

?>

Main Differences Between Type Juggling and Type Casting in php.

Feature of eachType Juggling in phpType Casting in php
Definition of eachType juggling help use to Automatic conversion of number of declare variables between multiple data typesHere type casting Explicit conversion of a declare variable to a specific type conversation
When it Happens I php scriptType juggling Happens automatically during operations or assignments in php operationtype casting Happens when explicitly requested by the php programmer
How much ControlType juggling provides Less control over when conversion occurs in php developmenttype casting provides you Full control over the conversion process in development
VersatileType juggling Used when performing operations with variables of different php data typestype casting Used when a variable must be explicitly converted to a specific data type

A summary of type casting and type juggling in PHP web development.

  • Type juggling in PHP – पीएचपी डेवलपमेंट में जरूरत के अनुसार प्रोग्राम ऑपरेशन के आधार पर पीएचपी ऑटोमेटिकली आर्डर में डाटा टाइप के बीच कन्वर्शन करता है।
  • Type casting in PHPपीएचपी डेवलपमेंट में प्रोग्रामर जरूरत पड़ने पर मैन्युअल कास्टिंग या settype() फ़ंक्शन को यूज़ करके किसी प्रोग्राम वैरिएबल को क्लियर आर्डर में किसी स्पेसिफिक डाटा टाइप में कास्ट कर सकते हैं।

Leave a Reply