Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- control
- Java
- while
- system
- Linux
- DB
- function
- Class
- javascript
- for
- instruction
- php
- architecture
- DS
- html
- github
- XML
- CSS
- Pipelining
- MIPS
- DATAPATH
- web
- MacOS
- data structure
- react
- DoM
- python
- Algorithm
- mysql
- computer
Archives
- Today
- Total
YYYEJI
[PHP] PHP의 1차원 Array 본문
728x90
Array란?
맵(map)으로 이루어진, 순서가 있는 집합을 의미합니다.
기본적은 문법은 아래와 같습니다.
$nums = array(1, 2, 3, 4, 5);
Array의 개수를 알고 싶을 땐 count() 함수를 이용합니다.
<!EOCTYPE html>
<body>
<h1>My first PHP page</h1>
<?php
$nums = array(1, 2, 3, 4, 5);
echo count($nums);
?>
</body>
Array의 value를 출력할 땐 index를 이용합니다.
<!EOCTYPE html>
<body>
<h1>My first PHP page</h1>
<?php
$nums = array(1, 2, 3, 4, 5);
echo "The number are ".$nums[0].", ".$nums[1].", ".$nums[2].", ".$nums[3]." and ".$nums[4];
?>
</body>
for문을 사용해서 array의 value를 출력하고 싶을 땐 아래와 같은 문법을 사용하시면 됩니다.
<!EOCTYPE html>
<body>
<h1>My first PHP page</h1>
<?php
$nums = array(1, 2, 3, 4, 5);
$arrlength = count($nums);
for ($x = 0; $x < $arrlength; $x++) {
echo $nums[$x];
echo "<br>";
}
?>
</body>
◡̈
'HTML(or XML) & CSS & JavaScript' 카테고리의 다른 글
[PHP] PHP의 Associative Array (0) | 2022.12.12 |
---|---|
[PHP] PHP의 다차원 Array (0) | 2022.12.12 |
[PHP] 함수 만들기 (0) | 2022.12.12 |
[PHP] Class 만들기 (0) | 2022.12.12 |
[PHP] PHP 변수 type 확인 (0) | 2022.12.12 |