{"id":15596,"date":"2020-07-01T06:52:50","date_gmt":"2020-07-01T06:52:50","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=15596"},"modified":"2022-04-13T15:58:38","modified_gmt":"2022-04-13T15:58:38","slug":"how-to-define-php-variable-type-conversion-operators","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/how-to-define-php-variable-type-conversion-operators\/","title":{"rendered":"How to define PHP variable type conversion operators?"},"content":{"rendered":"\n<p>In this blog, I am going to explain Variable Type &amp; Type Conversion in<strong> PHP<\/strong>.<br>variable type depends on the value of currently holds means when you declare a variable in <strong>PHP<\/strong>, You do not declare its type.<\/p>\n\n\n\n<p><strong>$value = &#8220;This is Variable&#8221;;    \/\/ assign string<br>echo $value;<\/strong><\/p>\n\n\n\n<p>you can change variable&#8217;s type by assigning a new value of different type.<\/p>\n\n\n\n<p><strong>$val = 44;    \/\/ integer string<br>echo $val;<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Automatic type conversion-<\/h3>\n\n\n\n<p>A variable type can depend upon the text in which it is used. Some functions and operators can be expect the value of a particular type convert automatically that type of its value.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/ajcotocus\/7815df7a970b9034f04c597ca5047ab0.js\"><\/script>\n\n\n\n<p><strong>Output-<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"701\" height=\"237\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/automatic-type-conversion-1.png\" alt=\"\" class=\"wp-image-15603\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/automatic-type-conversion-1.png 701w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/automatic-type-conversion-1-300x101.png 300w\" sizes=\"auto, (max-width: 701px) 100vw, 701px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">settype() \u2013 Change Variable\u2019s Data Type-<\/h3>\n\n\n\n<p>The function settype($value, &#8220;Type&#8221;) can clearly set the type of variable to type where the type&#8217;s value may be array, string, boolean integer, object, null. then uses of settype($value &#8220;Type&#8221;).<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/ajcotocus\/15ae7511005a78fe50ba1cdc96380e87.js\"><\/script>\n\n\n\n<p><strong>Output<\/strong>&#8211;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"571\" height=\"262\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/settype-variable.png\" alt=\"\" class=\"wp-image-15601\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/settype-variable.png 571w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/settype-variable-300x138.png 300w\" sizes=\"auto, (max-width: 571px) 100vw, 571px\" \/><\/figure>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_68936\"><figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube epyt-figure\"><div class=\"wp-block-embed__wrapper\"><iframe loading=\"lazy\"  id=\"_ytid_14513\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_68936\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>In this blog, I am going to explain Variable Type &amp; Type Conversion in PHP.variable type depends on the value of currently holds means when you declare a variable in PHP, You do not declare its type. $value = &#8220;This is Variable&#8221;; \/\/ assign stringecho $value; you can change variable&#8217;s type by assigning a new&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[5150],"tags":[6243,5892,5849,177,6228,5045],"class_list":["post-15596","post","type-post","status-publish","format-standard","hentry","category-php","tag-conversion","tag-define","tag-operators","tag-php","tag-php7","tag-variable"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/15596","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=15596"}],"version-history":[{"count":5,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/15596\/revisions"}],"predecessor-version":[{"id":24702,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/15596\/revisions\/24702"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=15596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=15596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=15596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}