{"id":375,"date":"2021-02-17T05:08:41","date_gmt":"2021-02-17T05:08:41","guid":{"rendered":"https:\/\/codeflarelimited.com\/blog\/?p=375"},"modified":"2021-05-20T14:09:56","modified_gmt":"2021-05-20T13:09:56","slug":"php-arrays","status":"publish","type":"post","link":"https:\/\/codeflarelimited.com\/blog\/php-arrays\/","title":{"rendered":"PHP Arrays"},"content":{"rendered":"\n<p>An array is a data structure that stores one or more similar type of values in a single value.<\/p>\n\n\n\n<p>For example, if you were to store 100 numbers, then instead of defining 100 variables, it is easy to define an array of 100 length. Each value in the array is accessed using an <em><strong>id<\/strong><\/em>, which is called <strong><em>array index.<\/em><\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/codeflarelimited.com\/blog\/2020\/11\/30\/working-with-arrays-in-java\/\" target=\"_blank\" rel=\"noreferrer noopener\">See arrays in Java<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-three-3-kinds-of-array\">Three (3) Kinds of Array<\/h3>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>Numeric Array<\/strong>: This refers to an array with a numeric index. Values are stored and accessed in a linear fashion.<\/li><li><strong>Associative Array<\/strong>: This refers to an array with strings as index. This stores element values in association with key values rather than in a strict linear index order.<\/li><li><strong>Multi-dimensional Array<\/strong>: This refers to an array that contains one or more arrays. Values are accessed using multiple indices.<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-numeric-array\">Numeric Array<\/h3>\n\n\n\n<p>These arrays can store numbers, strings and any object, but their index will be represented by numbers. By default the array index starts from 0.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\n$num = array(\"1\", \"2\", \"3\", \"4\", \"5\");\nforeach($num as $val){\necho $val;\n}\n?&gt;<\/code><\/pre>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link\" href=\"https:\/\/codeflarelimited.com\/catalogue\/backend\" target=\"_blank\" rel=\"noreferrer noopener\">begin your software development journey<\/a><\/div>\n<\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-associative-array\">Associative Array<\/h3>\n\n\n\n<p>Associative arrays are similar to numeric arrays in terms of functionality, but they are different in terms of their index. <\/p>\n\n\n\n<p>Associative arrays will have their index as string so that a strong association between key and values is established.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\n$salary = array(\n           \"John\" =&gt; 2000,\n           \"James\" =&gt; 1000,\n           \"Zara\" =&gt; 2500,\n           );\necho \"John's salary is \".$salary['John'];\n\/\/echo for the others\n?&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-multi-dimensional-array\">Multi-dimensional Array<\/h3>\n\n\n\n<p>A multi-dimensional array is one in which each element in the main array can also be an array, and each element in the sub-array can be an array as well. And it goes on and on.<\/p>\n\n\n\n<p>Values in the multi-dimensional array are accessed using multiple index.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\n$marks = array(\"John\" =&gt; array(\"Physics\" =&gt; 30, \"Math\" =&gt; 20, \"English\" =&gt; 10), \"Musa\" =&gt; array(\"Physics\" =&gt; 10, \"Math\" =&gt; 10, \"English\" =&gt; 10));\n\necho \"John's score in physics is \".$marks['John']['Physics'];\n?&gt;<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/www.php.net\/manual\/en\/book.array.php\" target=\"_blank\" rel=\"noreferrer noopener\">See PHP documentation for arrays<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>An array is a data structure that stores one or more similar type of values in a single<\/p>\n","protected":false},"author":1,"featured_media":376,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[87],"tags":[90,89],"class_list":["post-375","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-numeric-array","tag-php-arrays"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PHP Arrays<\/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:\/\/codeflarelimited.com\/blog\/php-arrays\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP Arrays\" \/>\n<meta property=\"og:description\" content=\"An array is a data structure that stores one or more similar type of values in a single\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codeflarelimited.com\/blog\/php-arrays\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/facebook.com\/codeflretech\" \/>\n<meta property=\"article:published_time\" content=\"2021-02-17T05:08:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-20T13:09:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2021\/02\/array.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1856\" \/>\n\t<meta property=\"og:image:height\" content=\"957\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"codeflare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codeflaretech\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/php-arrays\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/php-arrays\\\/\"},\"author\":{\"name\":\"codeflare\",\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/#\\\/schema\\\/person\\\/7e65653d49add95629f8c1053c5cd76a\"},\"headline\":\"PHP Arrays\",\"datePublished\":\"2021-02-17T05:08:41+00:00\",\"dateModified\":\"2021-05-20T13:09:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/php-arrays\\\/\"},\"wordCount\":258,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/php-arrays\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/array.jpg\",\"keywords\":[\"numeric array\",\"php arrays\"],\"articleSection\":[\"php\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/php-arrays\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/php-arrays\\\/\",\"url\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/php-arrays\\\/\",\"name\":\"PHP Arrays\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/php-arrays\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/php-arrays\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/array.jpg\",\"datePublished\":\"2021-02-17T05:08:41+00:00\",\"dateModified\":\"2021-05-20T13:09:56+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/php-arrays\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/php-arrays\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/php-arrays\\\/#primaryimage\",\"url\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/array.jpg\",\"contentUrl\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/array.jpg\",\"width\":1856,\"height\":957,\"caption\":\"software development training in abuja\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/php-arrays\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"php\",\"item\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/php\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PHP Arrays\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/\",\"name\":\"\",\"description\":\"Sustainable solutions\",\"publisher\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/#organization\",\"name\":\"Codeflare Limited\",\"url\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/codeflare.png\",\"contentUrl\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/codeflare.png\",\"width\":1040,\"height\":263,\"caption\":\"Codeflare Limited\"},\"image\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/#\\\/schema\\\/person\\\/7e65653d49add95629f8c1053c5cd76a\",\"name\":\"codeflare\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/59cef917c86d965eea581d2747f51bd6382003a68bfce7c8a4dfec98b4cd838d?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/59cef917c86d965eea581d2747f51bd6382003a68bfce7c8a4dfec98b4cd838d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/59cef917c86d965eea581d2747f51bd6382003a68bfce7c8a4dfec98b4cd838d?s=96&d=mm&r=g\",\"caption\":\"codeflare\"},\"description\":\"Latest tech news and coding tips.\",\"sameAs\":[\"https:\\\/\\\/codeflarelimited.com\\\/blog\",\"https:\\\/\\\/facebook.com\\\/codeflretech\",\"https:\\\/\\\/instagram.com\\\/codeflaretech\",\"https:\\\/\\\/x.com\\\/codeflaretech\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCuBLtiYqsajHdqw0uyt7Ofw?sub_confirmation=1\"],\"url\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/author\\\/watcher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP Arrays","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:\/\/codeflarelimited.com\/blog\/php-arrays\/","og_locale":"en_US","og_type":"article","og_title":"PHP Arrays","og_description":"An array is a data structure that stores one or more similar type of values in a single","og_url":"https:\/\/codeflarelimited.com\/blog\/php-arrays\/","article_author":"https:\/\/facebook.com\/codeflretech","article_published_time":"2021-02-17T05:08:41+00:00","article_modified_time":"2021-05-20T13:09:56+00:00","og_image":[{"width":1856,"height":957,"url":"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2021\/02\/array.jpg","type":"image\/jpeg"}],"author":"codeflare","twitter_card":"summary_large_image","twitter_creator":"@codeflaretech","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/codeflarelimited.com\/blog\/php-arrays\/#article","isPartOf":{"@id":"https:\/\/codeflarelimited.com\/blog\/php-arrays\/"},"author":{"name":"codeflare","@id":"https:\/\/codeflarelimited.com\/blog\/#\/schema\/person\/7e65653d49add95629f8c1053c5cd76a"},"headline":"PHP Arrays","datePublished":"2021-02-17T05:08:41+00:00","dateModified":"2021-05-20T13:09:56+00:00","mainEntityOfPage":{"@id":"https:\/\/codeflarelimited.com\/blog\/php-arrays\/"},"wordCount":258,"commentCount":0,"publisher":{"@id":"https:\/\/codeflarelimited.com\/blog\/#organization"},"image":{"@id":"https:\/\/codeflarelimited.com\/blog\/php-arrays\/#primaryimage"},"thumbnailUrl":"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2021\/02\/array.jpg","keywords":["numeric array","php arrays"],"articleSection":["php"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/codeflarelimited.com\/blog\/php-arrays\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/codeflarelimited.com\/blog\/php-arrays\/","url":"https:\/\/codeflarelimited.com\/blog\/php-arrays\/","name":"PHP Arrays","isPartOf":{"@id":"https:\/\/codeflarelimited.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/codeflarelimited.com\/blog\/php-arrays\/#primaryimage"},"image":{"@id":"https:\/\/codeflarelimited.com\/blog\/php-arrays\/#primaryimage"},"thumbnailUrl":"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2021\/02\/array.jpg","datePublished":"2021-02-17T05:08:41+00:00","dateModified":"2021-05-20T13:09:56+00:00","breadcrumb":{"@id":"https:\/\/codeflarelimited.com\/blog\/php-arrays\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codeflarelimited.com\/blog\/php-arrays\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codeflarelimited.com\/blog\/php-arrays\/#primaryimage","url":"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2021\/02\/array.jpg","contentUrl":"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2021\/02\/array.jpg","width":1856,"height":957,"caption":"software development training in abuja"},{"@type":"BreadcrumbList","@id":"https:\/\/codeflarelimited.com\/blog\/php-arrays\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codeflarelimited.com\/blog\/"},{"@type":"ListItem","position":2,"name":"php","item":"https:\/\/codeflarelimited.com\/blog\/php\/"},{"@type":"ListItem","position":3,"name":"PHP Arrays"}]},{"@type":"WebSite","@id":"https:\/\/codeflarelimited.com\/blog\/#website","url":"https:\/\/codeflarelimited.com\/blog\/","name":"","description":"Sustainable solutions","publisher":{"@id":"https:\/\/codeflarelimited.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codeflarelimited.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/codeflarelimited.com\/blog\/#organization","name":"Codeflare Limited","url":"https:\/\/codeflarelimited.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codeflarelimited.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2020\/11\/codeflare.png","contentUrl":"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2020\/11\/codeflare.png","width":1040,"height":263,"caption":"Codeflare Limited"},"image":{"@id":"https:\/\/codeflarelimited.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/codeflarelimited.com\/blog\/#\/schema\/person\/7e65653d49add95629f8c1053c5cd76a","name":"codeflare","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/59cef917c86d965eea581d2747f51bd6382003a68bfce7c8a4dfec98b4cd838d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/59cef917c86d965eea581d2747f51bd6382003a68bfce7c8a4dfec98b4cd838d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/59cef917c86d965eea581d2747f51bd6382003a68bfce7c8a4dfec98b4cd838d?s=96&d=mm&r=g","caption":"codeflare"},"description":"Latest tech news and coding tips.","sameAs":["https:\/\/codeflarelimited.com\/blog","https:\/\/facebook.com\/codeflretech","https:\/\/instagram.com\/codeflaretech","https:\/\/x.com\/codeflaretech","https:\/\/www.youtube.com\/channel\/UCuBLtiYqsajHdqw0uyt7Ofw?sub_confirmation=1"],"url":"https:\/\/codeflarelimited.com\/blog\/author\/watcher\/"}]}},"jetpack_featured_media_url":"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2021\/02\/array.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/posts\/375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/comments?post=375"}],"version-history":[{"count":2,"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/posts\/375\/revisions"}],"predecessor-version":[{"id":617,"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/posts\/375\/revisions\/617"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/media\/376"}],"wp:attachment":[{"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/media?parent=375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/categories?post=375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/tags?post=375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}