{"id":3648,"date":"2020-05-29T00:27:00","date_gmt":"2020-05-28T15:27:00","guid":{"rendered":"https:\/\/katblog.manadream.net\/?p=3648"},"modified":"2020-10-07T15:47:28","modified_gmt":"2020-10-07T06:47:28","slug":"what-are-array","status":"publish","type":"post","link":"https:\/\/katblog.manadream.net\/index.php\/2020\/05\/29\/what-are-array\/","title":{"rendered":"[PHP]What are Arrays?[Programming for Kids and Above #4]"},"content":{"rendered":"<p>Hello!<\/p>\n<p>I&#8217;m kat, the manager of &#8216;kat&#8217;s blog.&#8217;<\/p>\n<p>This time, which is the fourth installment of the &#8216;Programming Lessons&#8217; series, I will be talking about arrays.<\/p>\n<p>In my <a href=\"https:\/\/katblog.manadream.net\/index.php\/2020\/05\/02\/lets-calculate\/\">last article<\/a>, we tried entering one value in one variable, but actually you can also enter <span class=\"marker\">multiple values<\/span>.<\/p>\n<p>Let&#8217;s learn how to do that this time!<\/p>\n\n\n<h2 class=\"wp-block-heading\"><strong>What we will use this time<\/strong><\/h2>\n\n\n<p><div class=\"kaisetsu-box4\"><div class=\"kaisetsu-box4-title\">The programming language we will use this time<\/div><p><\/p>\n<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\">The programming environment we will use this time<\/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 doing this 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\">What are arrays?<\/h2>\n\n\n<p>I mentioned at the beginning, but <span class=\"marker\">arrays<\/span>&nbsp;are <span class=\"marker\">variables which can hold multiple values<\/span>.<\/p>\n\n\n<h3 class=\"wp-block-heading\">How to enter values<\/h3>\n\n\n<p>In the case of regular variables;<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n$number = 1;\n<\/pre><\/div>\n\n<p>you enter only one value like shown above,<\/p>\n<p>however for an array,<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n$numbers = &#x5B;1, 2, 3];\n<\/pre><\/div>\n\n<p>like shown above, you write in multiple values inside the [], while separating them with a &#8216;,&#8217;.<\/p>\n<p>Also, you can write it out as,<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n$numbers = array(1, 2, 3);\n<\/pre><\/div>\n\n<p>Even though how it is written is different, the meaning is the same as when we wrote it inside the [].<\/p>\n\n\n<h3 class=\"wp-block-heading\">How to acquire values<\/h3>\n\n\n<p>When acquiring values from normal variables, usually you can do this just by writing out the variable. However, in the case of arrays you need to attach a number after the variable. <span class=\"marker\">This number, such as [0] or [1], needs to be the number which has the value you wish to take (the number tells which order the value is in).<\/span><\/p>\n\n\n<div class=\"simple-box6\">\n\n\n<p>In the case of regular variables;<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n\n$number = 1;\necho $number;  \/\/ is the regular way to acquire variables.\n<\/pre><\/div>\n\n<p>The execution result will be displayed as &#8216;1&#8217;.<\/p>\n\n\n<\/div>\n\n\n\n<div class=\"simple-box6\">\n\n\n<p>How to acquire values from arrays<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n\n$numbers = &#x5B;1, 2, 3];   \/\/ in the zero position is the value '1,' in the one position is '2,' and in the two position is '3.'\necho $numbers&#x5B;1];       \/\/ this is acquiring the number one value '2.'\n<\/pre><\/div>\n\n<p>As some of you might have noticed already, the numbers start from <span class=\"marker\">zero<\/span>.<\/p>\n<p>So, because [1] is selected above, the <span class=\"marker\">number one<\/span> value, <span class=\"marker\">&#8216;2&#8217;<\/span> will be displayed on the screen.<\/p>\n\n\n<\/div>\n\n\n<p><div class=\"jin-iconbox green-iconbox\"><div class=\"jin-iconbox-icons\"><i class=\"jic jin-ifont-pencil jin-icons\"><\/i><\/div><div class=\"jin-iconbox-main green--border\">The [0(zero)], [1], which is put after an array, is called a &#8216;<span style=\"color: #3366ff;\">key<\/span>&#8216; in programming terminology.<\/p>\n<p>For instance, the <span style=\"color: #3366ff;\">keys<\/span> are 0,1,2 in the case of $numbers = [1, 2, 3].<\/p>\n<p>This phrase is used very often, so let&#8217;s try to remember it!<\/div><\/div><\/p>\n\n\n<h3 class=\"wp-block-heading\">Let&#8217;s enter letters into a value<\/h3>\n\n\n<p>You can put in <span class=\"marker\">letters<\/span> as well as <span class=\"marker\">numbers<\/span> into variables.<\/p>\n<p>The way to do this is almost the same as if you were putting in numbers, but you will need to surround the value with <span class=\"marker\">&#8216;(quotations)<\/span> or with <span class=\"marker\">&#8220;(double quotations)<\/span>.<\/p>\n<p>Now then, let&#8217;s try entering letters both into a variable as well as in an array.<\/p>\n\n\n<div class=\"simple-box6\">\n\n\n<p>In the case of regular variables,<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n\n$fruit = &quot;apple&quot;;\necho $fruit;         \/\/ &quot;apple&quot; is how it will be displayed.\n<\/pre><\/div>\n\n<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3677\" data-permalink=\"https:\/\/katblog.manadream.net\/index.php\/2020\/05\/29\/what-are-array\/variable\/\" data-orig-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/variable.png\" data-orig-size=\"1276,546\" 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=\"variable\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/variable-300x128.png\" data-large-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/variable-1024x438.png\" class=\"alignnone size-large wp-image-3677\" src=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/variable-1024x438.png\" alt=\"\" width=\"1024\" height=\"438\" srcset=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/variable-1024x438.png 1024w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/variable-300x128.png 300w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/variable-768x329.png 768w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/variable.png 1276w, https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/05\/variable-1024x438.png 856w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>In the case of an array;<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n\n$fruits = &#x5B;&quot;apple&quot;, &quot;orange&quot;, &quot;banana&quot;, &quot;strawberry&quot;];\necho $fruits&#x5B;1];        \/\/ &quot;orange&quot; is how it would be displayed.\n<\/pre><\/div>\n\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\n\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Final thoughts<\/h2>\n\n\n<p>We talked about arrays this time. They are used just as much as regular variables, so please make sure to remember them.<\/p>\n<p>Next time, I&#8217;ll be talking about <strong><span class=\"marker\">associative arrays<\/span><\/strong>. They are easier to use than arrays, so please look forward to it!<\/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--bc8c12192c2e795b0924b311eb642bef\"><a class=\"wp-block-button__link has-vivid-cyan-blue-color has-text-color\" href=\"https:\/\/katblog.manadream.net\/index.php\/2020\/05\/02\/lets-calculate\/\">&lt;&lt; Proceed to previous article<\/a><\/div>\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--96783ca935ff044207d29e14d4865a21\"><a class=\"wp-block-button__link has-vivid-cyan-blue-color has-text-color\" href=\"https:\/\/katblog.manadream.net\/index.php\/2020\/09\/03\/associative-arrays\/\">Proceed to next article &gt;&gt;<\/a><\/div>\n\n\n\n<p><\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello! I#8217;m kat, the manager of #8216;kat#8217;s blog.#8217; This time, which is the fourth installmen<\/p>\n","protected":false},"author":1,"featured_media":4141,"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=3648","_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-3648","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\/2019\/07\/balloon.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paUgnN-WQ","_links":{"self":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts\/3648"}],"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=3648"}],"version-history":[{"count":29,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts\/3648\/revisions"}],"predecessor-version":[{"id":3731,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts\/3648\/revisions\/3731"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/media\/4141"}],"wp:attachment":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/media?parent=3648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/categories?post=3648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/tags?post=3648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}