{"id":56,"date":"2025-03-09T05:40:22","date_gmt":"2025-03-09T05:40:22","guid":{"rendered":"https:\/\/techkubo.com\/php\/?p=56"},"modified":"2025-05-23T17:54:47","modified_gmt":"2025-05-23T17:54:47","slug":"php-casting","status":"publish","type":"post","link":"https:\/\/techkubo.com\/php\/php-casting\/","title":{"rendered":"PHP Casting"},"content":{"rendered":"\n<p>Sometimes you need to convert a variable from one data type to another, or you want a variable to have a specific data type. This process is known as casting.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Change Data Type<\/h2>\n\n\n\n<p>Casting in PHP is done with these statements:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>(string)<\/code> &#8211; Converts to data type String<\/li>\n\n\n\n<li><code>(int)<\/code> &#8211; Converts to data type Integer<\/li>\n\n\n\n<li><code>(float)<\/code> &#8211; Converts to data type Float<\/li>\n\n\n\n<li><code>(bool)<\/code> &#8211; Converts to data type Boolean<\/li>\n\n\n\n<li><code>(array)<\/code> &#8211; Converts to data type Array<\/li>\n\n\n\n<li><code>(object)<\/code> &#8211; Converts to data type Object<\/li>\n\n\n\n<li><code>(unset)<\/code> &#8211; Converts to data type NULL<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Cast to String<\/h2>\n\n\n\n<p>To cast a variable to a string, use the <code>(string)<\/code> statement:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">$gear = 5;       \/\/ Integer\n$speed = 120.5;  \/\/ Float\n$greeting = &quot;hello&quot;; \/\/ String\n$isFast = true;    \/\/ Boolean\n$notAvailable = NULL; \/\/ NULL\n\n$gear = (string) $gear;\n$speed = (string) $speed;\n$greeting = (string) $greeting;\n$isFast = (string) $isFast;\n$notAvailable = (string) $notAvailable;\n\n\/\/ To verify the type of any object in PHP, use the var_dump() function:\nvar_dump($gear);\nvar_dump($speed);\nvar_dump($greeting);\nvar_dump($isFast);\nvar_dump($notAvailable);<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cast to Integer<\/h2>\n\n\n\n<p>To cast a variable to an integer, use the <code>(int)<\/code> statement:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">$gear = 5;       \/\/ Integer\n$speed = 120.5;  \/\/ Float\n$distance = &quot;500 miles&quot;; \/\/ String\n$road = &quot;miles 500&quot;; \/\/ String\n$greeting = &quot;hello&quot;; \/\/ String\n$isFast = true;    \/\/ Boolean\n$notAvailable = NULL; \/\/ NULL\n\n$gear = (int) $gear;\n$speed = (int) $speed;\n$distance = (int) $distance;\n$road = (int) $road;\n$greeting = (int) $greeting;\n$isFast = (int) $isFast;\n$notAvailable = (int) $notAvailable;<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cast to Float<\/h2>\n\n\n\n<p>To cast a variable to a float, use the <code>(float)<\/code> statement:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">$gear = 5;       \/\/ Integer\n$speed = 120.5;  \/\/ Float\n$distance = &quot;500 miles&quot;; \/\/ String\n$road = &quot;miles 500&quot;; \/\/ String\n$greeting = &quot;hello&quot;; \/\/ String\n$isFast = true;    \/\/ Boolean\n$notAvailable = NULL; \/\/ NULL\n\n$gear = (float) $gear;\n$speed = (float) $speed;\n$distance = (float) $distance;\n$road = (float) $road;\n$greeting = (float) $greeting;\n$isFast = (float) $isFast;\n$notAvailable = (float) $notAvailable;<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cast to Boolean<\/h2>\n\n\n\n<p>To cast a variable to a boolean, use the <code>(bool)<\/code> statement:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">$gear = 5;       \/\/ Integer\n$speed = 120.5;  \/\/ Float\n$zero = 0;       \/\/ Integer\n$negative = -1;  \/\/ Integer\n$distance = 0.1; \/\/ Float\n$greeting = &quot;hello&quot;; \/\/ String\n$emptyString = &quot;&quot;;  \/\/ String\n$isFast = true;    \/\/ Boolean\n$notAvailable = NULL; \/\/ NULL\n\n$gear = (bool) $gear;\n$speed = (bool) $speed;\n$zero = (bool) $zero;\n$negative = (bool) $negative;\n$distance = (bool) $distance;\n$greeting = (bool) $greeting;\n$emptyString = (bool) $emptyString;\n$isFast = (bool) $isFast;\n$notAvailable = (bool) $notAvailable;<\/pre><\/div>\n\n\n\n<p>If a value is 0, NULL, false, or empty, casting it to a boolean converts it to <code>false<\/code>. Otherwise, it converts to <code>true<\/code>. Even -1 converts to <code>true<\/code>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cast to Array<\/h2>\n\n\n\n<p>To cast a variable to an array, use the <code>(array)<\/code> statement:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">$gear = 5;       \/\/ Integer\n$speed = 120.5;  \/\/ Float\n$greeting = &quot;hello&quot;; \/\/ String\n$isFast = true;    \/\/ Boolean\n$notAvailable = NULL; \/\/ NULL\n\n$gear = (array) $gear;\n$speed = (array) $speed;\n$greeting = (array) $greeting;\n$isFast = (array) $isFast;\n$notAvailable = (array) $notAvailable;<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Most data types convert into an indexed array with one element when cast to arrays. NULL values convert to an empty array.<\/p>\n\n\n\n<p><strong>Example: Converting Objects into Arrays<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">class Motorcycle {\n  public $brand;\n  public $model;\n  public function __construct($brand, $model) {\n    $this-&gt;brand = $brand;\n    $this-&gt;model = $model;\n  }\n  public function description() {\n    return &quot;My motorcycle is a &quot; . $this-&gt;brand . &quot; &quot; . $this-&gt;model . &quot;!&quot;;\n  }\n}\n\n$myMotorcycle = new Motorcycle(&quot;Honda&quot;, &quot;CB500&quot;);\n\n$myMotorcycle = (array) $myMotorcycle;\nvar_dump($myMotorcycle);<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Cast to Object<\/h3>\n\n\n\n<p>To cast a variable to an object, use the <code>(object)<\/code> statement:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">$gear = 5;       \/\/ Integer\n$speed = 120.5;  \/\/ Float\n$greeting = &quot;hello&quot;; \/\/ String\n$isFast = true;    \/\/ Boolean\n$notAvailable = NULL; \/\/ NULL\n\n$gear = (object) $gear;\n$speed = (object) $speed;\n$greeting = (object) $greeting;\n$isFast = (object) $isFast;\n$notAvailable = (object) $notAvailable;<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Most data types convert into an object with one property named &#8220;scalar&#8221; with the corresponding value. NULL values convert to an empty object.<\/p>\n\n\n\n<p><strong>Example: Converting Arrays into Objects<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">$brands = array(&quot;Honda&quot;, &quot;Yamaha&quot;, &quot;Suzuki&quot;); \/\/ Indexed array\n$models = array(&quot;CB500&quot;=&gt;&quot;500cc&quot;, &quot;R6&quot;=&gt;&quot;600cc&quot;, &quot;GSX&quot;=&gt;&quot;750cc&quot;); \/\/ Associative array\n\n$brands = (object) $brands;\n$models = (object) $models;<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cast to NULL<\/h2>\n\n\n\n<p>To cast a variable to NULL, use the <code>(unset)<\/code> statement:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">$gear = 5;       \/\/ Integer\n$speed = 120.5;  \/\/ Float\n$greeting = &quot;hello&quot;; \/\/ String\n$isFast = true;    \/\/ Boolean\n$notAvailable = NULL; \/\/ NULL\n\n$gear = (unset) $gear;\n$speed = (unset) $speed;\n$greeting = (unset) $greeting;\n$isFast = (unset) $isFast;\n$notAvailable = (unset) $notAvailable;<\/pre><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you need to convert a variable from one data type to another, or you want a variable to have [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-56","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PHP Casting - PHP Tutorial<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techkubo.com\/php\/php-casting\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP Casting - PHP Tutorial\" \/>\n<meta property=\"og:description\" content=\"Sometimes you need to convert a variable from one data type to another, or you want a variable to have [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techkubo.com\/php\/php-casting\/\" \/>\n<meta property=\"og:site_name\" content=\"PHP Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2025-03-09T05:40:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-23T17:54:47+00:00\" \/>\n<meta name=\"author\" content=\"Manong\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Manong\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/techkubo.com\/php\/php-casting\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/techkubo.com\/php\/php-casting\/\"},\"author\":{\"name\":\"Manong\",\"@id\":\"https:\/\/techkubo.com\/php\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965\"},\"headline\":\"PHP Casting\",\"datePublished\":\"2025-03-09T05:40:22+00:00\",\"dateModified\":\"2025-05-23T17:54:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/techkubo.com\/php\/php-casting\/\"},\"wordCount\":254,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/techkubo.com\/php\/#organization\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/techkubo.com\/php\/php-casting\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/techkubo.com\/php\/php-casting\/\",\"url\":\"https:\/\/techkubo.com\/php\/php-casting\/\",\"name\":\"PHP Casting - PHP Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/techkubo.com\/php\/#website\"},\"datePublished\":\"2025-03-09T05:40:22+00:00\",\"dateModified\":\"2025-05-23T17:54:47+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/techkubo.com\/php\/php-casting\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/techkubo.com\/php\/php-casting\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/techkubo.com\/php\/php-casting\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/techkubo.com\/php\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP Casting\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/techkubo.com\/php\/#website\",\"url\":\"https:\/\/techkubo.com\/php\/\",\"name\":\"PHP Tutorial\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/techkubo.com\/php\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/techkubo.com\/php\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/techkubo.com\/php\/#organization\",\"name\":\"PHP Tutorial\",\"url\":\"https:\/\/techkubo.com\/php\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/techkubo.com\/php\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/techkubo.com\/php\/wp-content\/uploads\/sites\/12\/2025\/04\/cropped-TechKubo-Logo-PNG.png\",\"contentUrl\":\"https:\/\/techkubo.com\/php\/wp-content\/uploads\/sites\/12\/2025\/04\/cropped-TechKubo-Logo-PNG.png\",\"width\":300,\"height\":220,\"caption\":\"PHP Tutorial\"},\"image\":{\"@id\":\"https:\/\/techkubo.com\/php\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/techkubo.com\/php\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965\",\"name\":\"Manong\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/techkubo.com\/php\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g\",\"caption\":\"Manong\"},\"sameAs\":[\"https:\/\/techkubo.com\"],\"url\":\"https:\/\/techkubo.com\/php\/author\/manong\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP Casting - PHP Tutorial","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techkubo.com\/php\/php-casting\/","og_locale":"en_US","og_type":"article","og_title":"PHP Casting - PHP Tutorial","og_description":"Sometimes you need to convert a variable from one data type to another, or you want a variable to have [&hellip;]","og_url":"https:\/\/techkubo.com\/php\/php-casting\/","og_site_name":"PHP Tutorial","article_published_time":"2025-03-09T05:40:22+00:00","article_modified_time":"2025-05-23T17:54:47+00:00","author":"Manong","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Manong","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techkubo.com\/php\/php-casting\/#article","isPartOf":{"@id":"https:\/\/techkubo.com\/php\/php-casting\/"},"author":{"name":"Manong","@id":"https:\/\/techkubo.com\/php\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965"},"headline":"PHP Casting","datePublished":"2025-03-09T05:40:22+00:00","dateModified":"2025-05-23T17:54:47+00:00","mainEntityOfPage":{"@id":"https:\/\/techkubo.com\/php\/php-casting\/"},"wordCount":254,"commentCount":0,"publisher":{"@id":"https:\/\/techkubo.com\/php\/#organization"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techkubo.com\/php\/php-casting\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techkubo.com\/php\/php-casting\/","url":"https:\/\/techkubo.com\/php\/php-casting\/","name":"PHP Casting - PHP Tutorial","isPartOf":{"@id":"https:\/\/techkubo.com\/php\/#website"},"datePublished":"2025-03-09T05:40:22+00:00","dateModified":"2025-05-23T17:54:47+00:00","breadcrumb":{"@id":"https:\/\/techkubo.com\/php\/php-casting\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techkubo.com\/php\/php-casting\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/techkubo.com\/php\/php-casting\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techkubo.com\/php\/"},{"@type":"ListItem","position":2,"name":"PHP Casting"}]},{"@type":"WebSite","@id":"https:\/\/techkubo.com\/php\/#website","url":"https:\/\/techkubo.com\/php\/","name":"PHP Tutorial","description":"","publisher":{"@id":"https:\/\/techkubo.com\/php\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techkubo.com\/php\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techkubo.com\/php\/#organization","name":"PHP Tutorial","url":"https:\/\/techkubo.com\/php\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techkubo.com\/php\/#\/schema\/logo\/image\/","url":"https:\/\/techkubo.com\/php\/wp-content\/uploads\/sites\/12\/2025\/04\/cropped-TechKubo-Logo-PNG.png","contentUrl":"https:\/\/techkubo.com\/php\/wp-content\/uploads\/sites\/12\/2025\/04\/cropped-TechKubo-Logo-PNG.png","width":300,"height":220,"caption":"PHP Tutorial"},"image":{"@id":"https:\/\/techkubo.com\/php\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/techkubo.com\/php\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965","name":"Manong","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techkubo.com\/php\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g","caption":"Manong"},"sameAs":["https:\/\/techkubo.com"],"url":"https:\/\/techkubo.com\/php\/author\/manong\/"}]}},"_links":{"self":[{"href":"https:\/\/techkubo.com\/php\/wp-json\/wp\/v2\/posts\/56"}],"collection":[{"href":"https:\/\/techkubo.com\/php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techkubo.com\/php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techkubo.com\/php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techkubo.com\/php\/wp-json\/wp\/v2\/comments?post=56"}],"version-history":[{"count":2,"href":"https:\/\/techkubo.com\/php\/wp-json\/wp\/v2\/posts\/56\/revisions"}],"predecessor-version":[{"id":191,"href":"https:\/\/techkubo.com\/php\/wp-json\/wp\/v2\/posts\/56\/revisions\/191"}],"wp:attachment":[{"href":"https:\/\/techkubo.com\/php\/wp-json\/wp\/v2\/media?parent=56"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techkubo.com\/php\/wp-json\/wp\/v2\/categories?post=56"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techkubo.com\/php\/wp-json\/wp\/v2\/tags?post=56"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}