{"id":249,"date":"2024-03-08T05:08:19","date_gmt":"2024-03-08T05:08:19","guid":{"rendered":"https:\/\/www.xopsschool.com\/tutorials\/?p=249"},"modified":"2024-03-08T05:10:33","modified_gmt":"2024-03-08T05:10:33","slug":"what-are-arrays-in-php","status":"publish","type":"post","link":"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/","title":{"rendered":"What are arrays in PHP?"},"content":{"rendered":"\n<p>An array is a special variable that we use to store or hold more than one value in a single variable without having to create more variables to store those values. It is a versatile and fundamental data structure used for organizing, storing, and manipulating data. PHP arrays can hold various types of data, including strings, numbers, and even other arrays.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/www.xopsschool.com\/tutorials\/wp-content\/uploads\/2024\/03\/php-arrays-1024x576.jpg\" alt=\"\" class=\"wp-image-250\" style=\"width:597px;height:auto\" srcset=\"https:\/\/www.xopsschool.com\/tutorials\/wp-content\/uploads\/2024\/03\/php-arrays-1024x576.jpg 1024w, https:\/\/www.xopsschool.com\/tutorials\/wp-content\/uploads\/2024\/03\/php-arrays-300x169.jpg 300w, https:\/\/www.xopsschool.com\/tutorials\/wp-content\/uploads\/2024\/03\/php-arrays-768x432.jpg 768w, https:\/\/www.xopsschool.com\/tutorials\/wp-content\/uploads\/2024\/03\/php-arrays.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong> There are three types of  PHP Arrays : <\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Indexed arrays<\/li>\n\n\n\n<li>Associative arrays<\/li>\n\n\n\n<li>Multidimensional arrays<\/li>\n<\/ul>\n\n\n\n<p><strong>Indexed arrays<\/strong> <\/p>\n\n\n\n<p>PHP indexed array is an array which is represented by an index number by default. All elements of an array are represented by an index number which starts from 0.indexed array can store numbers.<\/p>\n\n\n\n<p><strong>Code :-<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> $numericArray = array(\"Apple\", \"Banana\", \"Orange\");\r\n\/\/ or\r\n$numericArray = &#91;\"Apple\", \"Banana\", \"Orange\"];\r\n\r\n\/\/ Accessing elements\r\necho $numericArray&#91;0]; <\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong> <\/p>\n\n\n\n<p>Apple<\/p>\n\n\n\n<p><strong>Associative arrays<\/strong><\/p>\n\n\n\n<p>An associative array is created using the array() function with a set of key-value pairs, where each key represents a unique identifier for a value in the array. These keys can be of any data type, including strings, integers, and floats.<\/p>\n\n\n\n<p><strong>Code <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\r\n  $student = array(\r\n    \"name\" => \"Yash Agarwal\",\r\n    \"age\" => 21,\r\n    \"stream\" => \"Computer Science\"\r\n);\r\n\r\nforeach($student as $key => $value) {\r\n    echo $key . \": \" . $value . \"&lt;br>\";\r\n}\r\n\r\n<\/code><\/pre>\n\n\n\n<p><strong>Output :-<\/strong><\/p>\n\n\n\n<p>name: Yash Agarwal<br>age: 21<br>stream: Computer Science<\/p>\n\n\n\n<p><strong>Multidimensional arrays<\/strong><\/p>\n\n\n\n<p>A multi-dimensional array of each element in the main array can also be an array. And each element in the sub-array can be an array, and so on. Values in the multi-dimensional array are accessed using multiple indexes.  <\/p>\n\n\n\n<p><strong>Code <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n$marks = array(\n   \"kevin\" => array (\n      \"physics\" => 95,\n      \"maths\" => 90,\n   ),\n   \"ryan\" => array (\n      \"physics\" => 92,\n      \"maths\" => 97,\n   ),\n);\n   echo \"Marks for kevin in physics : \" ;\n   echo $marks&#91;'kevin']&#91;'physics'] . \"\\n\";\n   echo \"Marks for ryan in maths : \";\n   echo $marks&#91;'ryan']&#91;'maths'] . \"\\n\";\n?>\n<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<p>Marks for kevin in physics : 95<br>Marks for ryan in maths : 97<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>An array is a special variable that we use to store or hold more than one value in a single variable without having to create more variables to store those values. It is a versatile and fundamental data structure used for organizing, storing, and manipulating data. PHP arrays can hold various types of data, including &#8230; <a title=\"What are arrays in PHP?\" class=\"read-more\" href=\"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/\" aria-label=\"Read more about What are arrays in PHP?\">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":[20],"tags":[],"class_list":["post-249","post","type-post","status-publish","format-standard","hentry","category-arrays-in-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What are arrays in PHP? - 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\/what-are-arrays-in-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What are arrays in PHP? - XOps Tutorials!!!\" \/>\n<meta property=\"og:description\" content=\"An array is a special variable that we use to store or hold more than one value in a single variable without having to create more variables to store those values. It is a versatile and fundamental data structure used for organizing, storing, and manipulating data. PHP arrays can hold various types of data, including ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/\" \/>\n<meta property=\"og:site_name\" content=\"XOps Tutorials!!!\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-08T05:08:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-08T05:10:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.xopsschool.com\/tutorials\/wp-content\/uploads\/2024\/03\/php-arrays-1024x576.jpg\" \/>\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=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/\"},\"author\":{\"name\":\"ritik hansda\",\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/#\/schema\/person\/c0119ddd2d27ea9cd476e809c8294ba7\"},\"headline\":\"What are arrays in PHP?\",\"datePublished\":\"2024-03-08T05:08:19+00:00\",\"dateModified\":\"2024-03-08T05:10:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/\"},\"wordCount\":223,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.xopsschool.com\/tutorials\/wp-content\/uploads\/2024\/03\/php-arrays-1024x576.jpg\",\"articleSection\":[\"Arrays in PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/\",\"url\":\"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/\",\"name\":\"What are arrays in PHP? - XOps Tutorials!!!\",\"isPartOf\":{\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.xopsschool.com\/tutorials\/wp-content\/uploads\/2024\/03\/php-arrays-1024x576.jpg\",\"datePublished\":\"2024-03-08T05:08:19+00:00\",\"dateModified\":\"2024-03-08T05:10:33+00:00\",\"author\":{\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/#\/schema\/person\/c0119ddd2d27ea9cd476e809c8294ba7\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/#primaryimage\",\"url\":\"https:\/\/www.xopsschool.com\/tutorials\/wp-content\/uploads\/2024\/03\/php-arrays.jpg\",\"contentUrl\":\"https:\/\/www.xopsschool.com\/tutorials\/wp-content\/uploads\/2024\/03\/php-arrays.jpg\",\"width\":1200,\"height\":675},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.xopsschool.com\/tutorials\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What are arrays in PHP?\"}]},{\"@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":"What are arrays in PHP? - 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\/what-are-arrays-in-php\/","og_locale":"en_US","og_type":"article","og_title":"What are arrays in PHP? - XOps Tutorials!!!","og_description":"An array is a special variable that we use to store or hold more than one value in a single variable without having to create more variables to store those values. It is a versatile and fundamental data structure used for organizing, storing, and manipulating data. PHP arrays can hold various types of data, including ... Read more","og_url":"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/","og_site_name":"XOps Tutorials!!!","article_published_time":"2024-03-08T05:08:19+00:00","article_modified_time":"2024-03-08T05:10:33+00:00","og_image":[{"url":"https:\/\/www.xopsschool.com\/tutorials\/wp-content\/uploads\/2024\/03\/php-arrays-1024x576.jpg","type":"","width":"","height":""}],"author":"ritik hansda","twitter_card":"summary_large_image","twitter_misc":{"Written by":"ritik hansda","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/#article","isPartOf":{"@id":"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/"},"author":{"name":"ritik hansda","@id":"https:\/\/www.xopsschool.com\/tutorials\/#\/schema\/person\/c0119ddd2d27ea9cd476e809c8294ba7"},"headline":"What are arrays in PHP?","datePublished":"2024-03-08T05:08:19+00:00","dateModified":"2024-03-08T05:10:33+00:00","mainEntityOfPage":{"@id":"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/"},"wordCount":223,"commentCount":0,"image":{"@id":"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.xopsschool.com\/tutorials\/wp-content\/uploads\/2024\/03\/php-arrays-1024x576.jpg","articleSection":["Arrays in PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/","url":"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/","name":"What are arrays in PHP? - XOps Tutorials!!!","isPartOf":{"@id":"https:\/\/www.xopsschool.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/#primaryimage"},"image":{"@id":"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.xopsschool.com\/tutorials\/wp-content\/uploads\/2024\/03\/php-arrays-1024x576.jpg","datePublished":"2024-03-08T05:08:19+00:00","dateModified":"2024-03-08T05:10:33+00:00","author":{"@id":"https:\/\/www.xopsschool.com\/tutorials\/#\/schema\/person\/c0119ddd2d27ea9cd476e809c8294ba7"},"breadcrumb":{"@id":"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/#primaryimage","url":"https:\/\/www.xopsschool.com\/tutorials\/wp-content\/uploads\/2024\/03\/php-arrays.jpg","contentUrl":"https:\/\/www.xopsschool.com\/tutorials\/wp-content\/uploads\/2024\/03\/php-arrays.jpg","width":1200,"height":675},{"@type":"BreadcrumbList","@id":"https:\/\/www.xopsschool.com\/tutorials\/what-are-arrays-in-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.xopsschool.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"What are arrays in PHP?"}]},{"@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\/249","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=249"}],"version-history":[{"count":2,"href":"https:\/\/www.xopsschool.com\/tutorials\/wp-json\/wp\/v2\/posts\/249\/revisions"}],"predecessor-version":[{"id":252,"href":"https:\/\/www.xopsschool.com\/tutorials\/wp-json\/wp\/v2\/posts\/249\/revisions\/252"}],"wp:attachment":[{"href":"https:\/\/www.xopsschool.com\/tutorials\/wp-json\/wp\/v2\/media?parent=249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xopsschool.com\/tutorials\/wp-json\/wp\/v2\/categories?post=249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xopsschool.com\/tutorials\/wp-json\/wp\/v2\/tags?post=249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}