{"id":3712,"date":"2020-09-03T00:49:52","date_gmt":"2020-09-02T15:49:52","guid":{"rendered":"https:\/\/katblog.manadream.net\/?p=3712"},"modified":"2020-10-11T22:07:51","modified_gmt":"2020-10-11T13:07:51","slug":"associative-arrays","status":"publish","type":"post","link":"https:\/\/katblog.manadream.net\/index.php\/2020\/09\/03\/associative-arrays\/","title":{"rendered":"[PHP]Let&#8217;s Try Using Associative Arrays![Programming for Kids and Above #5]"},"content":{"rendered":"<p>Hello!<\/p>\n<p>I&#8217;m kat, the manager of &#8216;kat&#8217;s blog.<\/p>\n<p>This time, which is the fifth installment of the &#8216;Programming Lessons&#8217; series, I will be talking about <span class=\"marker\">associative arrays<\/span>.<\/p>\n<p>Last time on the <a href=\"https:\/\/katblog.manadream.net\/index.php\/2020\/05\/29\/what-are-array\/\">fourth article<\/a>, we learned about arrays, in which you can put in multiple values, but this time we will be learning about <span class=\"marker\">associative arrays<\/span> which are even more easier to use.<\/p>\n<p>It is used a lot in programming, so let&#8217;s try to remember it!<\/p>\n\n\n<h2 class=\"wp-block-heading\"><strong>What we will use this time<\/strong><\/h2>\n\n\n<p><\/p>\n<p><div class=\"kaisetsu-box4\"><div class=\"kaisetsu-box4-title\">programming language<\/div><p>This time we will use the following programming language to write out a program.<\/p>\n<div class=\"simple-box7\">\n<p>\u30fbPHP<\/p>\n<\/div>\n<p><\/p><\/div><\/p>\n<p><div class=\"kaisetsu-box4\"><div class=\"kaisetsu-box4-title\">programming environment<\/div><p><\/p>\n<p>Let&#8217;s use the paiza website which is listed below for executing the program.<\/p>\n<p><span class=\"twobutton\"><span class=\"color-button02\"><a href=\"https:\/\/paiza.io\/en\/projects\/new?locale=en-us\" target=\"_blank\" rel=\"noopener noreferrer\">paiza website<\/a><\/span><\/span><\/p>\n<p>For those who are using this website for the first time, the way to use it is listed in the page below, so please check it out.<\/p>\n<p>https:\/\/katblog.manadream.net\/index.php\/2020\/06\/09\/how-to-use-paiza-io\/<\/p>\n<p><\/p><\/div><\/p>\n\n\n<h2 class=\"wp-block-heading\">Reviewing arrays<\/h2>\n\n\n<p>Last time I mentioned that arrays are like a container that can hold multiple values. For example, the first value could be &#8216;apple,&#8217; and the second value could be &#8216;orange.&#8217;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3679\" data-permalink=\"https:\/\/katblog.manadream.net\/index.php\/2020\/05\/29\/what-are-array\/array\/\" data-orig-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/array.png\" data-orig-size=\"1244,596\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"array\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/array-300x144.png\" data-large-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/array-1024x491.png\" class=\"alignnone size-large wp-image-3679\" src=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/array-1024x491.png\" alt=\"\" width=\"1024\" height=\"491\" srcset=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/array-1024x491.png 1024w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/array-300x144.png 300w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/array-768x368.png 768w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/array.png 1244w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/array-1024x491.png 856w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>Also, I explained that arrays each have a number (starting from 0), and each of them are called a &#8216;key.&#8217;<\/p>\n<p>In the case of arrays, because the keys are automatically attached, you do not need to enter them in the source code.<\/p>\n<p>Now then, let&#8217;s review the source code of arrays.<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n $array = &#x5B;'apple', 'orange', 'banana', 'strawberry']; \/\/ Automatically the keys \u300c0\u300d\u300c1\u300d\u300c2\u300d\u300c3\u300dare attached\n \n echo $array&#x5B;1];\n<\/pre><\/div>\n\n<p>When you run the above source code, keys are automatically attached, so &#8216;<span class=\"marker\">orange<\/span>&#8216; which has the key of &#8216;1&#8217; should be displayed.<\/p>\n<div class=\"concept-box6\">\n<p>Arrays are used a lot when creating groups of things that are the same kind.<\/p>\n<p>For instance, a group of fruit (apple, orange, banana, etc.), a group of animals (dog, cat, elephant, etc.), or a group of vehicles (car, train, airplane, etc.).<\/p>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">What are associative arrays?<\/h2>\n\n\n<p>Just like arrays, associative arrays are <strong>a container which you can enter multiple values<\/strong>.<\/p>\n<p>However, the difference between arrays are that <span class=\"marker\">you can name the keys as you like.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3728\" data-permalink=\"https:\/\/katblog.manadream.net\/index.php\/2020\/09\/03\/associative-arrays\/%e3%82%b9%e3%82%af%e3%83%aa%e3%83%bc%e3%83%b3%e3%82%b7%e3%83%a7%e3%83%83%e3%83%88_2020-09-03_0_23_46\/\" data-orig-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/09\/5fb1c26a4a8b8dc8dcb35b93a736c3aa.png\" data-orig-size=\"1234,554\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-03_0_23_46\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/09\/5fb1c26a4a8b8dc8dcb35b93a736c3aa-300x135.png\" data-large-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/09\/5fb1c26a4a8b8dc8dcb35b93a736c3aa-1024x460.png\" class=\"alignnone size-large wp-image-3728\" src=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/09\/5fb1c26a4a8b8dc8dcb35b93a736c3aa-1024x460.png\" alt=\"\" width=\"1024\" height=\"460\" srcset=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/09\/5fb1c26a4a8b8dc8dcb35b93a736c3aa-1024x460.png 1024w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/09\/5fb1c26a4a8b8dc8dcb35b93a736c3aa-300x135.png 300w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/09\/5fb1c26a4a8b8dc8dcb35b93a736c3aa-768x345.png 768w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/09\/5fb1c26a4a8b8dc8dcb35b93a736c3aa.png 1234w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/09\/5fb1c26a4a8b8dc8dcb35b93a736c3aa-1024x460.png 856w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>Looking at the example above, in the key titled &#8216;name,&#8217; there is &#8216;Bobby,&#8217; and in the &#8216;age&#8217; key there is the value &#8217;10.&#8217;<\/p>\n<p>In this example, <span class=\"marker\">the information of a person has been put together as an associative array.<\/span><\/p>\n<p>Because the keys are letters instead of numbers, you can understand the information just by looking at the keys.<\/p>\n<p>Now then, let&#8217;s take a look at the source code of an associative array.<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n &lt;?php\n $user = &#x5B;\n  'name' =&gt; 'Bobby',\n  'age' =&gt; '10',\n  'gender' =&gt; 'male',\n  'favorite color' =&gt; 'blue'\n ];\n  \n echo $user&#x5B;'gender'];\n<\/pre><\/div>\n\n<p>If you run the source code above, the &#8216;<span class=\"marker\">male<\/span>&#8216; value which is in the &#8216;gender&#8217; key will be displayed.<\/p>\n<div class=\"concept-box6\">\n<p>As shown, associative arrays are useful to <span class=\"marker2\">keep together the information of people and things<\/span>.<\/p>\n<p>For instance, product (name of product, price, expiration date, etc.) ,etc.<\/p>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">Final thoughts<\/h2>\n\n\n<p>Thank you for reading to the end of this lesson this time as well.<\/p>\n<p>In this lesson we covered arrays and associative arrays. It isn&#8217;t a matter of which is better, and it is important to be able to use whichever matches your purpose best.<\/p>\n<p>Arrays and associative arrays <span class=\"marker\">always pop up<\/span> when doing programming, so let&#8217;s make sure to remember them!<\/p>\n<p>See you next time!<\/p>\n\n\n<br>\n\n\n\n<div class=\"wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-1 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-button alignleft is-style-outline is-style-outline--5260538a1ebc403a437846dedfa86296\"><a class=\"wp-block-button__link has-vivid-cyan-blue-color has-text-color\" href=\"https:\/\/katblog.manadream.net\/index.php\/2020\/05\/29\/what-are-array\/\">&lt;&lt; previous article<\/a><\/div>\n\n\n\n<p><\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-button alignright is-style-outline is-style-outline--71dc686be9d8c2e033c5993635454c15\"><a class=\"wp-block-button__link has-vivid-cyan-blue-color has-text-color\" href=\"https:\/\/katblog.manadream.net\/index.php\/2020\/09\/03\/connecting-letters\/\">next article &gt;&gt;<\/a><\/div>\n\n\n\n<p><\/p>\n<\/div>\n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello! I#8217;m kat, the manager of #8216;kat#8217;s blog. This time, which is the fifth installment of the<\/p>\n","protected":false},"author":1,"featured_media":4157,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_locale":"ja","_original_post":"https:\/\/katblog.manadream.net\/?p=3712","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[102],"tags":[107,108],"class_list":["post-3712","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming-lessons","tag-english","tag-programming","ja"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/10\/array2.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paUgnN-XS","_links":{"self":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts\/3712"}],"collection":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/comments?post=3712"}],"version-history":[{"count":17,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts\/3712\/revisions"}],"predecessor-version":[{"id":3943,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts\/3712\/revisions\/3943"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/media\/4157"}],"wp:attachment":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/media?parent=3712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/categories?post=3712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/tags?post=3712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}