Array variables and associative arrays compiled by beginners for beginners

Thanks. Until now, I have created bulletin boards, etc. after learning, but I have been impatient for a span of 5 months. "Fluffy understanding" tells me that "○○ functions can be implemented with ○○", but I can't implement this one by myself without the power of Google teacher. Because the detailed understanding of each one is sparse From now on, I will post it on Qiita as a place for output in order to deeply understand the basics of the basics.

While deepening your understanding by referring to dozens of sites and books by using Google teacher yourself

  1. Actually write the code
  2. Put together in your notebook so that you can see it in your own words someday.
  3. Finally, tell Qiita so that other people can see it.

[What is an array]

An image of organizing multiple (property) data together and putting them in one large box. 333.png Output result: Ice

Summary of how to call

-The group of each blue box is called a property.

-Here, all parts of $ box are called [array].

-The automatically assigned subscripts are called [keys].

・ The parts of ice cream, chocolate ice cream, and curry-flavored ice cream are called [value].

Problem ![ee.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/677104/95a84dc4-21aa-928b-8f0d-0216616d8385.png)

The correct answer will come out as soon as you scroll, so try answering without scrolling down from here.

Correct answer: 2.3.4.1

  • Properties are also called elements, and arrays are also called indexes.

Problem 2

python


Hamburger array variable
・ Teriyaki Burger/Bacon lettuce burger/Pancake
The above three hamburgers[value]To store in the above order
Finally, display the Teriyaki Burger in the output result.

First of all, do it yourself. The answer will come out by pressing the link below. https://paiza.io/projects/pik0u6YBKOv40ZuMP-pG6g

next,$Break the Teriyaki burger and pancake from the Hamburger array variable and display them in the output result.
https://paiza.io/projects/pik0u6YBKOv40ZuMP-pG6g

There are multiple ways to break a line, so if you can output a line break other than the above URL method, it's OK! !!

By the way, if you want to include a variable in a character string as shown in the above URL, use "" (double quotation mark). The difference between double quotes and single quotes is that the URL below is very easy to understand! https://qiita.com/bitcoinjpnnet/items/64458299eaeefbacab44

How to display all the values stored in the

array in the output result? </ h2>

Use the foreach statement.

[What is a foreach statement]
Data stored in (list) or (array)[Also called element or value]Described against[program]Processed
A loop statement that has the power to execute repeatedly.

$box = ['ice','チョコice','カレー味ice'];
foreach($box as $value) {
    echo $value;
}
Output result: Ice chocolate ice curry flavored ice cream

It will end repeatedly when all the stored data is output.

Also, if you want to output the subscript [key] as well

foreach ($box as $key=>$value){
echo "$key=>$value \n";
}

Output result:
0=>ice
1=>Chocolate ice cream
2=>Curry flavored ice cream

It's a review. If you want to expand the variable in the character string, enclose it in double quotation marks. \ n means a line break. For Mac users, half-width [option key + ¥].

The $ value part is an arbitrary name.

Problem 3
Display all the values stored in the Hamburger array variable in the output result.

answer https://paiza.io/projects/pik0u6YBKOv40ZuMP-pG6g

Display all the values and keys stored in the Hamburger array variable in the output result.
conditions
Make a line break.
comma/Put a comma

Display result example
Key=>value,
Key=>value,
Key=>value,

answer https://paiza.io/projects/pik0u6YBKOv40ZuMP-pG6g

However, there are multiple ways to do it.

Isn't this a good understanding of arrays? If you are new to arrays, you may not understand it yet. If you search Google teacher for "What is an array?", It will come up quite a lot.

Next, I would like to deepen my understanding of associative arrays.

What is an associative array?

Any character string can be assigned to the key. -Character string (enclosed in quotation marks) ·integer

Good points of associative array

-Since the key is an arbitrary character string, it is easy to see and understand if you use a character string that has the same meaning as the value! Example: Apple => apple car => car

-One small box (also called a property called an element) can have two meanings with a key and a value. Example: If you want to manage customer contacts and names Example:'○○ company Kobayashi-sama'=> xxx-xxxx-xxxx (this is a phone number)

Let's try and remember!

It is assigned to the key of the associative array, but it should be noted

・ True false ・ ・ ・ Assigned to a key, but true= 1 false =Automatically converted to 0
・ Decimal point ・ ・ ・ Assigned to a key, but automatically converted to a truncated integer


Let's try and remember! https://paiza.io/projects/pik0u6YBKOv40ZuMP-pG6g

Associative arrays are also a family of arrays, so if you can understand arrays, you can understand associative arrays.

Next time, I will write an article that outputs an array with multiple output methods and understands loop processing etc. together.

Recommended Posts

Array variables and associative arrays compiled by beginners for beginners
Java for beginners, expressions and operators 1
Java for beginners, expressions and operators 2
Object-oriented course for beginners sent by beginners
Classes and instances Java for beginners
[For beginners] Difference between Java and Kotlin
Kantai Collection Java # 1 Classes and Objects [For Beginners]
[Java] Understand in 10 minutes! Associative array and HashMap
[For beginners] About lambda expressions and Stream API