{"id":238,"date":"2024-03-05T18:19:32","date_gmt":"2024-03-05T18:19:32","guid":{"rendered":"https:\/\/www.xopsschool.com\/tutorials\/?p=238"},"modified":"2024-03-05T18:19:32","modified_gmt":"2024-03-05T18:19:32","slug":"the-user-defined-data-types-are","status":"publish","type":"post","link":"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/","title":{"rendered":"The user-defined  data types are"},"content":{"rendered":"\n<ul class=\"wp-block-list\">\n<li>Array<\/li>\n\n\n\n<li>Objects<\/li>\n<\/ul>\n\n\n\n<p><strong>Array <\/strong><\/p>\n\n\n\n<p>An array is formally defined as an indexed collection of data values. Each index (also known as the key) of an array is unique and references a corresponding value.<br><\/p>\n\n\n\n<p><strong>Example :<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> &lt;!DOCTYPE html>\r\n&lt;html lang=\"en\">\r\n&lt;head>\r\n    &lt;title>PHP Arrays&lt;\/title>\r\n&lt;\/head>\r\n&lt;body>\r\n\r\n&lt;?php\r\n$colors = array(\"Red\", \"Green\", \"Blue\");\r\nvar_dump($colors);\r\necho \"&lt;br>\";\r\n \r\n$color_codes = array(\r\n    \"Red\" => \"#ff0000\",\r\n    \"Green\" => \"#00ff00\",\r\n    \"Blue\" => \"#0000ff\"\r\n);\r\nvar_dump($color_codes);\r\n?>\r\n\r\n&lt;\/body>\r\n&lt;\/html>\n\n<strong>Output:-<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>array(3) { &#91;0]=> string(3) \"Red\" &#91;1]=> string(5) \"Green\" &#91;2]=> string(4) \"Blue\" }\r\narray(3) { &#91;\"Red\"]=> string(7) \"#ff0000\" &#91;\"Green\"]=> string(7) \"#00ff00\" &#91;\"Blue\"]=> string(7) \"#0000ff\"\n<\/code><\/pre>\n\n\n\n<p><strong>Objects<\/strong><\/p>\n\n\n\n<p>An Object is an individual instance of the data structure defined by a class. We define a class once and then make many objects that belong to it. Objects are also known as instances<\/p>\n\n\n\n<p><strong>Example : <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> \r\n&lt;!DOCTYPE html>\r\n&lt;html lang=\"en\">\r\n&lt;head>\r\n    &lt;meta charset=\"UTF-8\">\r\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\r\n    &lt;title>Car Information&lt;\/title>\r\n&lt;\/head>\r\n&lt;body>\r\n\r\n&lt;?php\r\n\r\n\/\/ Define a simple class\r\nclass Car {\r\n    \/\/ Properties\r\n    public $brand;\r\n    public $model;\r\n\r\n    \/\/ Constructor\r\n    public function __construct($brand, $model) {\r\n        $this->brand = $brand;\r\n        $this->model = $model;\r\n    }\r\n\r\n    \/\/ Method\r\n    public function startEngine() {\r\n        return \"Engine started for {$this->brand} {$this->model}.\";\r\n    }\r\n}\r\n\r\n\/\/ Instantiate objects based on the class\r\n$car1 = new Car(\"Toyota\", \"Camry\");\r\n$car2 = new Car(\"Ford\", \"Mustang\");\r\n\r\n\/\/ Access and manipulate object properties\r\n$car1->brand = \"Honda\";\r\n\r\n\/\/ Call object methods\r\n$message1 = $car1->startEngine();\r\n$message2 = $car2->startEngine();\r\n?>\r\n\r\n&lt;!-- Display the output within the HTML structure -->\r\n&lt;h1>Car Information&lt;\/h1>\r\n\r\n&lt;p>&lt;?php echo $message1; ?>&lt;\/p>\r\n&lt;p>&lt;?php echo $message2; ?>&lt;\/p>\r\n\r\n&lt;\/body>\r\n&lt;\/html>\r\n\r<\/code><\/pre>\n\n\n\n<p><strong>Output :-<\/strong><\/p>\n\n\n\n<p>Car Information<br>Engine started for Honda Camry.<br>Engine started for Ford Mustang.<\/p>\n\n\n\n<p><strong>The special data types are<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>NULL<\/li>\n\n\n\n<li>Resource<\/li>\n<\/ul>\n\n\n\n<p><strong>Null<\/strong><\/p>\n\n\n\n<p>In PHP, NULL is a special constant that represents the absence of a value or an uninitialized variable. It is a data type on its own and is used to indicate that a variable has no assigned value.<\/p>\n\n\n\n<p><strong>Example :<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> \r\n&lt;!DOCTYPE html>\r\n&lt;html lang=\"en\">\r\n&lt;head>\r\n    &lt;meta charset=\"UTF-8\">\r\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\r\n    &lt;title>NULL&lt;\/title>\r\n&lt;\/head>\r\n&lt;body>\r\n\r\n&lt;?php\r\n$name = NULL;\r\nif ($name === NULL) {\r\n    echo '&lt;p> variable is NULL.&lt;\/p>';\r\n}\r\n?>\r\n\r\n&lt;\/body>\r\n&lt;\/html>\r\n<strong>\nOutput:<\/strong>\n\nvariable is NULL.\n<\/code><\/pre>\n\n\n\n<p><strong>Resource<\/strong><\/p>\n\n\n\n<p>A resource in PHP is a special data type that represents a handle to external entities, such as files, database connections, network sockets, and more. Resources are typically created and manipulated by functions provided by PHP extensions or external libraries.<br><br><strong>Example :-<\/strong>  <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> &lt;!DOCTYPE html>\r\n&lt;html lang=\"en\">\r\n&lt;head>\r\n    &lt;meta charset=\"UTF-8\">\r\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\r\n    &lt;title>File Handling Example&lt;\/title>\r\n&lt;\/head>\r\n&lt;body>\r\n\r\n&lt;?php\r\n\r\n\/\/ Open a file and get a file handle resource\r\n$fileHandle = fopen('example.txt', 'r');\r\n\r\n\/\/ Check if the variable is a resource\r\nif (is_resource($fileHandle)) {\r\n    echo '&lt;p>File handle is a resource.&lt;\/p>';\r\n\r\n    \/\/ Read content from the file\r\n    $content = fread($fileHandle, filesize('example.txt'));\r\n    echo '&lt;p>File content: ' . $content . '&lt;\/p>';\r\n\r\n    \/\/ Close the file handle to release the resource\r\n    fclose($fileHandle);\r\n} else {\r\n    echo '&lt;p>Not a valid resource.&lt;\/p>';\r\n}\r\n\r\n?>\r\n\r\n&lt;\/body>\r\n&lt;\/html>\r\n\n<strong>Output :- <\/strong>\n\nNot a valid resource.<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Array An array is formally defined as an indexed collection of data values. Each index (also known as the key) of an array is unique and references a corresponding value. Example : Objects An Object is an individual instance of the data structure defined by a class. We define a class once and then make &#8230; <a title=\"The user-defined  data types are\" class=\"read-more\" href=\"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/\" aria-label=\"Read more about The user-defined  data types are\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-238","post","type-post","status-publish","format-standard","hentry","category-basic-php-syntax"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>The user-defined data types are - XOps Tutorials!!!<\/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:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The user-defined data types are - XOps Tutorials!!!\" \/>\n<meta property=\"og:description\" content=\"Array An array is formally defined as an indexed collection of data values. Each index (also known as the key) of an array is unique and references a corresponding value. Example : Objects An Object is an individual instance of the data structure defined by a class. We define a class once and then make ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/\" \/>\n<meta property=\"og:site_name\" content=\"XOps Tutorials!!!\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-05T18:19:32+00:00\" \/>\n<meta name=\"author\" content=\"ritik hansda\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"ritik hansda\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/\"},\"author\":{\"name\":\"ritik hansda\",\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/#\/schema\/person\/c0119ddd2d27ea9cd476e809c8294ba7\"},\"headline\":\"The user-defined data types are\",\"datePublished\":\"2024-03-05T18:19:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/\"},\"wordCount\":176,\"commentCount\":0,\"articleSection\":[\"Basic PHP Syntax\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/\",\"url\":\"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/\",\"name\":\"The user-defined data types are - XOps Tutorials!!!\",\"isPartOf\":{\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/#website\"},\"datePublished\":\"2024-03-05T18:19:32+00:00\",\"author\":{\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/#\/schema\/person\/c0119ddd2d27ea9cd476e809c8294ba7\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.xopsschool.com\/tutorials\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The user-defined data types are\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/#website\",\"url\":\"https:\/\/www.xopsschool.com\/tutorials\/\",\"name\":\"XOps Tutorials!!!\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.xopsschool.com\/tutorials\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/#\/schema\/person\/c0119ddd2d27ea9cd476e809c8294ba7\",\"name\":\"ritik hansda\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6fe0bc437410899c524975272622377e50e726108b1ad03f7b4488f734304fce?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6fe0bc437410899c524975272622377e50e726108b1ad03f7b4488f734304fce?s=96&d=mm&r=g\",\"caption\":\"ritik hansda\"},\"url\":\"https:\/\/www.xopsschool.com\/tutorials\/author\/ritikhansda\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The user-defined data types are - XOps Tutorials!!!","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:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/","og_locale":"en_US","og_type":"article","og_title":"The user-defined data types are - XOps Tutorials!!!","og_description":"Array An array is formally defined as an indexed collection of data values. Each index (also known as the key) of an array is unique and references a corresponding value. Example : Objects An Object is an individual instance of the data structure defined by a class. We define a class once and then make ... Read more","og_url":"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/","og_site_name":"XOps Tutorials!!!","article_published_time":"2024-03-05T18:19:32+00:00","author":"ritik hansda","twitter_card":"summary_large_image","twitter_misc":{"Written by":"ritik hansda","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/#article","isPartOf":{"@id":"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/"},"author":{"name":"ritik hansda","@id":"https:\/\/www.xopsschool.com\/tutorials\/#\/schema\/person\/c0119ddd2d27ea9cd476e809c8294ba7"},"headline":"The user-defined data types are","datePublished":"2024-03-05T18:19:32+00:00","mainEntityOfPage":{"@id":"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/"},"wordCount":176,"commentCount":0,"articleSection":["Basic PHP Syntax"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/","url":"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/","name":"The user-defined data types are - XOps Tutorials!!!","isPartOf":{"@id":"https:\/\/www.xopsschool.com\/tutorials\/#website"},"datePublished":"2024-03-05T18:19:32+00:00","author":{"@id":"https:\/\/www.xopsschool.com\/tutorials\/#\/schema\/person\/c0119ddd2d27ea9cd476e809c8294ba7"},"breadcrumb":{"@id":"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.xopsschool.com\/tutorials\/the-user-defined-data-types-are\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.xopsschool.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"The user-defined data types are"}]},{"@type":"WebSite","@id":"https:\/\/www.xopsschool.com\/tutorials\/#website","url":"https:\/\/www.xopsschool.com\/tutorials\/","name":"XOps Tutorials!!!","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.xopsschool.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.xopsschool.com\/tutorials\/#\/schema\/person\/c0119ddd2d27ea9cd476e809c8294ba7","name":"ritik hansda","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.xopsschool.com\/tutorials\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6fe0bc437410899c524975272622377e50e726108b1ad03f7b4488f734304fce?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6fe0bc437410899c524975272622377e50e726108b1ad03f7b4488f734304fce?s=96&d=mm&r=g","caption":"ritik hansda"},"url":"https:\/\/www.xopsschool.com\/tutorials\/author\/ritikhansda\/"}]}},"_links":{"self":[{"href":"https:\/\/www.xopsschool.com\/tutorials\/wp-json\/wp\/v2\/posts\/238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xopsschool.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xopsschool.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xopsschool.com\/tutorials\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xopsschool.com\/tutorials\/wp-json\/wp\/v2\/comments?post=238"}],"version-history":[{"count":1,"href":"https:\/\/www.xopsschool.com\/tutorials\/wp-json\/wp\/v2\/posts\/238\/revisions"}],"predecessor-version":[{"id":241,"href":"https:\/\/www.xopsschool.com\/tutorials\/wp-json\/wp\/v2\/posts\/238\/revisions\/241"}],"wp:attachment":[{"href":"https:\/\/www.xopsschool.com\/tutorials\/wp-json\/wp\/v2\/media?parent=238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xopsschool.com\/tutorials\/wp-json\/wp\/v2\/categories?post=238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xopsschool.com\/tutorials\/wp-json\/wp\/v2\/tags?post=238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}