[{"data":1,"prerenderedAt":697},["ShallowReactive",2],{"content-all-\u002Fphp\u002Fphp-fundamental\u002Fcasting-convertions":3,"related-\u002Fphp\u002Fphp-fundamental\u002Fcasting-convertions":418,"sidebar-content":646},[4],{"_path":5,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":10,"tags":11,"date":16,"weight":17,"body":18,"_type":412,"_id":413,"_source":414,"_file":415,"_stem":416,"_extension":417},"\u002Fphp\u002Fphp-fundamental\u002Fcasting-convertions","php-fundamental",false,"","PHP Casting and Conversions","Learning about PHP casting and conversions",[12,13,14,15],"php","backend","casting","conversions","2026-05-30",6,{"type":19,"children":20,"toc":405},"root",[21,29,35,42,47,91,103,215,296,302,307,388,394,399],{"type":22,"tag":23,"props":24,"children":26},"element","h2",{"id":25},"php-casting-and-conversions",[27],{"type":28,"value":9},"text",{"type":22,"tag":30,"props":31,"children":32},"p",{},[33],{"type":28,"value":34},"In PHP, casting and conversions are used to change the data type of a variable. This can be done explicitly using casting operators or implicitly through type juggling. Understanding how to cast and convert data types is essential for writing robust and error-free PHP code.",{"type":22,"tag":36,"props":37,"children":39},"h3",{"id":38},"explicit-casting",[40],{"type":28,"value":41},"Explicit Casting",{"type":22,"tag":30,"props":43,"children":44},{},[45],{"type":28,"value":46},"You can explicitly cast a variable to a different data type using casting operators. The syntax for explicit casting is as follows:",{"type":22,"tag":48,"props":49,"children":52},"pre",{"className":50,"code":51,"language":12,"meta":8,"style":8},"language-php shiki shiki-themes github-light github-dark","$variable = (type) $value;\n",[53],{"type":22,"tag":54,"props":55,"children":56},"code",{"__ignoreMap":8},[57],{"type":22,"tag":58,"props":59,"children":62},"span",{"class":60,"line":61},"line",1,[63,69,75,80,86],{"type":22,"tag":58,"props":64,"children":66},{"style":65},"--shiki-default:#24292E;--shiki-dark:#E1E4E8",[67],{"type":28,"value":68},"$variable ",{"type":22,"tag":58,"props":70,"children":72},{"style":71},"--shiki-default:#D73A49;--shiki-dark:#F97583",[73],{"type":28,"value":74},"=",{"type":22,"tag":58,"props":76,"children":77},{"style":65},[78],{"type":28,"value":79}," (",{"type":22,"tag":58,"props":81,"children":83},{"style":82},"--shiki-default:#005CC5;--shiki-dark:#79B8FF",[84],{"type":28,"value":85},"type",{"type":22,"tag":58,"props":87,"children":88},{"style":65},[89],{"type":28,"value":90},") $value;\n",{"type":22,"tag":30,"props":92,"children":93},{},[94,96,101],{"type":28,"value":95},"Where ",{"type":22,"tag":54,"props":97,"children":99},{"className":98},[],[100],{"type":28,"value":85},{"type":28,"value":102}," can be one of the following:",{"type":22,"tag":104,"props":105,"children":106},"ul",{},[107,127,145,156,174,185,196],{"type":22,"tag":108,"props":109,"children":110},"li",{},[111,117,119,125],{"type":22,"tag":54,"props":112,"children":114},{"className":113},[],[115],{"type":28,"value":116},"int",{"type":28,"value":118}," or ",{"type":22,"tag":54,"props":120,"children":122},{"className":121},[],[123],{"type":28,"value":124},"integer",{"type":28,"value":126},": Casts to an integer.",{"type":22,"tag":108,"props":128,"children":129},{},[130,136,137,143],{"type":22,"tag":54,"props":131,"children":133},{"className":132},[],[134],{"type":28,"value":135},"float",{"type":28,"value":118},{"type":22,"tag":54,"props":138,"children":140},{"className":139},[],[141],{"type":28,"value":142},"double",{"type":28,"value":144},": Casts to a floating-point number.",{"type":22,"tag":108,"props":146,"children":147},{},[148,154],{"type":22,"tag":54,"props":149,"children":151},{"className":150},[],[152],{"type":28,"value":153},"string",{"type":28,"value":155},": Casts to a string.",{"type":22,"tag":108,"props":157,"children":158},{},[159,165,166,172],{"type":22,"tag":54,"props":160,"children":162},{"className":161},[],[163],{"type":28,"value":164},"bool",{"type":28,"value":118},{"type":22,"tag":54,"props":167,"children":169},{"className":168},[],[170],{"type":28,"value":171},"boolean",{"type":28,"value":173},": Casts to a boolean.",{"type":22,"tag":108,"props":175,"children":176},{},[177,183],{"type":22,"tag":54,"props":178,"children":180},{"className":179},[],[181],{"type":28,"value":182},"array",{"type":28,"value":184},": Casts to an array.",{"type":22,"tag":108,"props":186,"children":187},{},[188,194],{"type":22,"tag":54,"props":189,"children":191},{"className":190},[],[192],{"type":28,"value":193},"object",{"type":28,"value":195},": Casts to an object.",{"type":22,"tag":108,"props":197,"children":198},{},[199,205,207,213],{"type":22,"tag":54,"props":200,"children":202},{"className":201},[],[203],{"type":28,"value":204},"unset",{"type":28,"value":206},": Casts to ",{"type":22,"tag":54,"props":208,"children":210},{"className":209},[],[211],{"type":28,"value":212},"NULL",{"type":28,"value":214},".",{"type":22,"tag":48,"props":216,"children":218},{"className":50,"code":217,"language":12,"meta":8,"style":8},"$value = \"123\";\n$intValue = (int) $value; \u002F\u002F Casts to integer\necho $intValue; \u002F\u002F Output: 123\n",[219],{"type":22,"tag":54,"props":220,"children":221},{"__ignoreMap":8},[222,245,277],{"type":22,"tag":58,"props":223,"children":224},{"class":60,"line":61},[225,230,234,240],{"type":22,"tag":58,"props":226,"children":227},{"style":65},[228],{"type":28,"value":229},"$value ",{"type":22,"tag":58,"props":231,"children":232},{"style":71},[233],{"type":28,"value":74},{"type":22,"tag":58,"props":235,"children":237},{"style":236},"--shiki-default:#032F62;--shiki-dark:#9ECBFF",[238],{"type":28,"value":239}," \"123\"",{"type":22,"tag":58,"props":241,"children":242},{"style":65},[243],{"type":28,"value":244},";\n",{"type":22,"tag":58,"props":246,"children":248},{"class":60,"line":247},2,[249,254,258,262,266,271],{"type":22,"tag":58,"props":250,"children":251},{"style":65},[252],{"type":28,"value":253},"$intValue ",{"type":22,"tag":58,"props":255,"children":256},{"style":71},[257],{"type":28,"value":74},{"type":22,"tag":58,"props":259,"children":260},{"style":65},[261],{"type":28,"value":79},{"type":22,"tag":58,"props":263,"children":264},{"style":71},[265],{"type":28,"value":116},{"type":22,"tag":58,"props":267,"children":268},{"style":65},[269],{"type":28,"value":270},") $value; ",{"type":22,"tag":58,"props":272,"children":274},{"style":273},"--shiki-default:#6A737D;--shiki-dark:#6A737D",[275],{"type":28,"value":276},"\u002F\u002F Casts to integer\n",{"type":22,"tag":58,"props":278,"children":280},{"class":60,"line":279},3,[281,286,291],{"type":22,"tag":58,"props":282,"children":283},{"style":82},[284],{"type":28,"value":285},"echo",{"type":22,"tag":58,"props":287,"children":288},{"style":65},[289],{"type":28,"value":290}," $intValue; ",{"type":22,"tag":58,"props":292,"children":293},{"style":273},[294],{"type":28,"value":295},"\u002F\u002F Output: 123\n",{"type":22,"tag":36,"props":297,"children":299},{"id":298},"implicit-conversions",[300],{"type":28,"value":301},"Implicit Conversions",{"type":22,"tag":30,"props":303,"children":304},{},[305],{"type":28,"value":306},"PHP also performs implicit conversions, also known as type juggling, when it encounters a situation where a specific data type is expected. For example, when you use a string in a mathematical operation, PHP will automatically convert it to a number if possible.",{"type":22,"tag":48,"props":308,"children":310},{"className":50,"code":309,"language":12,"meta":8,"style":8},"$value = \"10\";\n$result = $value + 5; \u002F\u002F Implicitly converts \"10\" to 10\necho $result; \u002F\u002F Output: 15\n",[311],{"type":22,"tag":54,"props":312,"children":313},{"__ignoreMap":8},[314,334,371],{"type":22,"tag":58,"props":315,"children":316},{"class":60,"line":61},[317,321,325,330],{"type":22,"tag":58,"props":318,"children":319},{"style":65},[320],{"type":28,"value":229},{"type":22,"tag":58,"props":322,"children":323},{"style":71},[324],{"type":28,"value":74},{"type":22,"tag":58,"props":326,"children":327},{"style":236},[328],{"type":28,"value":329}," \"10\"",{"type":22,"tag":58,"props":331,"children":332},{"style":65},[333],{"type":28,"value":244},{"type":22,"tag":58,"props":335,"children":336},{"class":60,"line":247},[337,342,346,351,356,361,366],{"type":22,"tag":58,"props":338,"children":339},{"style":65},[340],{"type":28,"value":341},"$result ",{"type":22,"tag":58,"props":343,"children":344},{"style":71},[345],{"type":28,"value":74},{"type":22,"tag":58,"props":347,"children":348},{"style":65},[349],{"type":28,"value":350}," $value ",{"type":22,"tag":58,"props":352,"children":353},{"style":71},[354],{"type":28,"value":355},"+",{"type":22,"tag":58,"props":357,"children":358},{"style":82},[359],{"type":28,"value":360}," 5",{"type":22,"tag":58,"props":362,"children":363},{"style":65},[364],{"type":28,"value":365},"; ",{"type":22,"tag":58,"props":367,"children":368},{"style":273},[369],{"type":28,"value":370},"\u002F\u002F Implicitly converts \"10\" to 10\n",{"type":22,"tag":58,"props":372,"children":373},{"class":60,"line":279},[374,378,383],{"type":22,"tag":58,"props":375,"children":376},{"style":82},[377],{"type":28,"value":285},{"type":22,"tag":58,"props":379,"children":380},{"style":65},[381],{"type":28,"value":382}," $result; ",{"type":22,"tag":58,"props":384,"children":385},{"style":273},[386],{"type":28,"value":387},"\u002F\u002F Output: 15\n",{"type":22,"tag":36,"props":389,"children":391},{"id":390},"conclusion",[392],{"type":28,"value":393},"Conclusion",{"type":22,"tag":30,"props":395,"children":396},{},[397],{"type":28,"value":398},"Understanding PHP casting and conversions is crucial for managing data types effectively in your applications. Whether you need to explicitly cast a variable or rely on implicit conversions, being aware of how PHP handles data types will help you avoid common pitfalls and write more efficient code. Always consider the context in which you are working with variables and choose the appropriate casting or conversion method to ensure your code behaves as expected.",{"type":22,"tag":400,"props":401,"children":402},"style",{},[403],{"type":28,"value":404},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":8,"searchDepth":279,"depth":279,"links":406},[407],{"id":25,"depth":247,"text":9,"children":408},[409,410,411],{"id":38,"depth":279,"text":41},{"id":298,"depth":279,"text":301},{"id":390,"depth":279,"text":393},"markdown","content:php:php-fundamental:casting-convertions.md","content","php\u002Fphp-fundamental\u002Fcasting-convertions.md","php\u002Fphp-fundamental\u002Fcasting-convertions","md",[419,427,435,440,446,455,460,465,470,475,480,489,495,500,505,510,515,520,526,534,542,547,554,559,565,571,579,585,591,598,604,610,617,629,635,640],{"_path":420,"title":421,"description":422,"tags":423,"date":426},"\u002Fcpp","C++ \u002F CPP","C++ notes, snippets, and references",[424,425],"cpp","c++","2026-05-05",{"_path":428,"title":429,"description":430,"tags":431,"date":434},"\u002Fdata-structure-algorithm\u002Farray-manipulation\u002Ffor-looping","For Looping in Python","Using for loops to manipulate arrays in Python.",[432,13,433],"python","arrays","2026-03-18",{"_path":436,"title":437,"description":438,"tags":439,"date":434},"\u002Fdata-structure-algorithm\u002Farray-manipulation\u002Fwhile-looping","While Looping in Python","Using while loops to manipulate arrays in Python.",[432,13,433],{"_path":441,"title":442,"description":443,"tags":444,"date":445},"\u002Fdata-structure-algorithm\u002Fassignments","Assignments","Assignments in Python for competitive programming.",[432,13],"2026-04-10",{"_path":447,"title":448,"description":449,"tags":450,"date":454},"\u002Fdata-structure-algorithm\u002Fbuzzword","Buzzword List DSA","Common terms and concepts in data structures and algorithms.",[451,452,453],"dsa","algorithms","data-structures","2026-04-03",{"_path":456,"title":457,"description":458,"tags":459,"date":445},"\u002Fdata-structure-algorithm\u002Fdata-type","Data Types","Data types in Python for competitive programming.",[432,13],{"_path":461,"title":462,"description":463,"tags":464,"date":445},"\u002Fdata-structure-algorithm\u002Fhash-map","Hash Map","Hash map implementation in Python for competitive programming.",[432,13],{"_path":466,"title":467,"description":468,"tags":469,"date":445},"\u002Fdata-structure-algorithm\u002Finput-output","Input and Output","Handling input and output in Python for competitive programming.",[432,13],{"_path":471,"title":472,"description":473,"tags":474,"date":434},"\u002Fdata-structure-algorithm\u002Fmath-library\u002Fsum","Sum Elements","Using for loops to sum elements in Python.",[432,13,433],{"_path":476,"title":477,"description":478,"tags":479,"date":434},"\u002Fdata-structure-algorithm\u002Fmath-library\u002Fsummary","Summary","Summary of the math library in Python.",[432,13,433],{"_path":481,"title":482,"description":483,"tags":484,"date":488},"\u002Fdocker\u002Fcheat-sheets","Docker Cheat Sheets","Cheat sheets for frequently used Docker commands and concepts",[485,486,487],"docker","devops","infrastructure","2026-05-01",{"_path":490,"title":491,"description":492,"tags":493,"date":494},"\u002Fdocker\u002Fdocker-dasar\u002Fdocker-container","Docker Container","Introduction to Docker containers and their usage",[485,486,487],"2026-03-12",{"_path":496,"title":497,"description":498,"tags":499,"date":494},"\u002Fdocker\u002Fdocker-dasar\u002Fdocker-execution","Docker Execution","Introduction to Docker execution and their usage",[485,486,487],{"_path":501,"title":502,"description":503,"tags":504,"date":494},"\u002Fdocker\u002Fdocker-dasar\u002Fdocker-image","Docker Image","Introduction to Docker images and their usage",[485,486,487],{"_path":506,"title":507,"description":508,"tags":509,"date":494},"\u002Fdocker\u002Fdocker-dasar\u002Fdocker-logging","Docker Logging","Introduction to Docker logging and their usage",[485,486,487],{"_path":511,"title":512,"description":513,"tags":514,"date":494},"\u002Fdocker\u002Fdocker-prerequisites\u002Fdocker-installation","Docker Installation","Introduction to Docker installation and their usage",[485,486,487],{"_path":516,"title":517,"description":518,"tags":519,"date":494},"\u002Fdocker\u002Fresources","Docker Resources","Collection of Docker resources for learning and reference",[485,486,487],{"_path":521,"title":522,"description":523,"tags":524,"date":426},"\u002Fjava","Java","Java notes, snippets, and references",[525],"java",{"_path":527,"title":528,"description":529,"tags":530,"date":494},"\u002Fjavascript\u002Fpromises","Promise Patterns","Common JavaScript promise patterns and async\u002Fawait usage",[531,532,533],"javascript","frontend","async",{"_path":535,"title":536,"description":537,"tags":538,"date":426},"\u002Fjenkins","Jenkins","Jenkins notes, snippets, and references",[539,540,541],"jenkins","ci","cd",{"_path":543,"title":544,"description":545,"tags":546,"date":434},"\u002Fphp\u002Farrays","PHP Array Functions","Essential PHP array functions and patterns",[12,13,433],{"_path":548,"title":549,"description":550,"tags":551,"date":553},"\u002Fphp\u002Fpatterns\u002Fsingleton","Singleton Pattern","Implementing the singleton pattern in PHP",[12,552,13],"patterns","2026-03-13",{"_path":555,"title":556,"description":557,"tags":558,"date":16},"\u002Fphp\u002Fphp-fundamental\u002Farray-map","PHP Array and Map","Essential PHP array and map functions and their usage",[12,13,433],{"_path":560,"title":561,"description":562,"tags":563,"date":16},"\u002Fphp\u002Fphp-fundamental\u002Fcomments","PHP Comments","Essential PHP comment operations",[12,13,564],"comments",{"_path":566,"title":567,"description":568,"tags":569,"date":16},"\u002Fphp\u002Fphp-fundamental\u002Fdatatypes","PHP Data Types","Essential PHP data types and their usage",[12,13,570],"data types",{"_path":572,"title":573,"description":574,"tags":575,"date":16},"\u002Fphp\u002Fphp-fundamental\u002Fexpression-statement-block","PHP Expressions, Statements, and Blocks","Essential PHP expressions, statements, and blocks",[12,13,576,577,578],"expressions","statements","blocks",{"_path":580,"title":581,"description":582,"tags":583,"date":16},"\u002Fphp\u002Fphp-fundamental\u002Fflow-control","PHP Flow Control","Essential PHP flow control structures and patterns",[12,13,584],"flow control",{"_path":586,"title":587,"description":588,"tags":589,"date":16},"\u002Fphp\u002Fphp-fundamental\u002Ffunctions","PHP Functions","Essential PHP functions and their usage",[12,13,590],"functions",{"_path":592,"title":593,"description":594,"tags":595,"date":16},"\u002Fphp\u002Fphp-fundamental\u002Finclude-require","PHP Include and Require","Understanding PHP include and require statements",[12,13,596,597],"include","require",{"_path":599,"title":600,"description":601,"tags":602,"date":16},"\u002Fphp\u002Fphp-fundamental\u002Fintroduction","PHP Introduction","An introduction to PHP programming language and its fundamentals",[12,13,603],"introduction",{"_path":605,"title":606,"description":607,"tags":608,"date":16},"\u002Fphp\u002Fphp-fundamental\u002Foperator","PHP Operators","Essential PHP operators and their usage",[12,13,609],"operators",{"_path":611,"title":612,"description":613,"tags":614,"date":16},"\u002Fphp\u002Fphp-fundamental\u002Foutput-input","PHP Output & Input","Learning about PHP output and input methods",[12,13,615,616],"output","input",{"_path":618,"title":619,"description":620,"tags":621,"date":16},"\u002Fphp\u002Fphp-fundamental\u002Fvariables","PHP Variables","Essential PHP variables, constants, magic constants, and variable scope",[12,13,622,623,624,625,626,627,628],"variables","constants","magic constants","scope","global","local","static",{"_path":630,"title":631,"description":632,"tags":633,"date":634},"\u002Fphp\u002Freferences","PHP References (&)","Useful PHP reference snippets and patterns",[12,13],"2026-03-19",{"_path":636,"title":637,"description":638,"tags":639,"date":426},"\u002Fpython","Python","Python notes, snippets, and references",[432],{"_path":641,"title":642,"description":643,"tags":644,"date":426},"\u002Frust","Rust","Rust notes, snippets, and references",[645],"rust",[647,648,650,651,652,653,654,655,656,658,659,661,662,664,666,668,669,670,671,672,673,674,675,677,678,679,681,683,684,686,688,689,691,692,694,695,696],{"_path":420,"title":421,"weight":61},{"_path":428,"title":429,"weight":649},10,{"_path":436,"title":437,"weight":649},{"_path":441,"title":442,"weight":279},{"_path":447,"title":448,"weight":61},{"_path":456,"title":457,"weight":247},{"_path":461,"title":462,"weight":649},{"_path":466,"title":467,"weight":61},{"_path":471,"title":472,"weight":657},20,{"_path":476,"title":477,"weight":649},{"_path":481,"title":482,"weight":660},100,{"_path":490,"title":491,"weight":657},{"_path":496,"title":497,"weight":663},22,{"_path":501,"title":502,"weight":665},21,{"_path":506,"title":507,"weight":667},23,{"_path":511,"title":512,"weight":649},{"_path":516,"title":517,"weight":61},{"_path":521,"title":522,"weight":61},{"_path":527,"title":528},{"_path":535,"title":536,"weight":61},{"_path":543,"title":544,"weight":61},{"_path":548,"title":549},{"_path":555,"title":556,"weight":676},9,{"_path":5,"title":9,"weight":17},{"_path":560,"title":561,"weight":279},{"_path":566,"title":567,"weight":680},5,{"_path":572,"title":573,"weight":682},8,{"_path":580,"title":581,"weight":649},{"_path":586,"title":587,"weight":685},11,{"_path":592,"title":593,"weight":687},12,{"_path":599,"title":600,"weight":61},{"_path":605,"title":606,"weight":690},7,{"_path":611,"title":612,"weight":247},{"_path":618,"title":619,"weight":693},4,{"_path":630,"title":631,"weight":247},{"_path":636,"title":637,"weight":61},{"_path":641,"title":642,"weight":61},1780160024391]