#csv->cells(row?: number, rows?: bool, column?: any, columns?: bool, header?: bool, as?: type) → any
셀들입니다. 단독으로 쓰거나
rows와 함께 쓰면 모든 행을, columns와 함께 쓰면 모든 열을 가져옵니다. row: 는 행 하나를 0부터 세어 고릅니다(-1은 마지막 행). column: 은 헤더 이름이나 0부터 세는 번호로 열 하나를 고릅니다. 행과 열을 함께 지정하면 둘이 만나는 셀 하나를 가져오고, rows와 column: 을 함께 쓰면 모든 행에서 그 열의 셀을 가져옵니다. 행은 첫 줄을 키로 하는 맵이며, 헤더가 없으면 셀의 리스트입니다. 열은 헤더를 키로 하는 리스트들의 맵이며, 헤더가 없으면 리스트들의 리스트입니다. 헤더가 없을 때 행의 길이는 서로 다를 수 있으며, 열을 가져올 때는 그 열에 닿지 않는 짧은 행을 건너뜁니다. 첫 줄은 모든 셀이 숫자가 아닌 한 헤더로 봅니다. 선택하려면 header 또는 not header를 지정하세요. 숫자로 적힌 셀은 숫자로 반환합니다. 셀은 쉼표, 탭, 세미콜론, 또는 숫자 사이의 공백으로 나뉠 수 있습니다. as: 에 타입을 지정하면 결과를 검사하고 그 타입으로 변환합니다.| 매개변수 | 받는 값 |
|---|---|
row 선택 사항 | number |
rows 선택 사항 | 플래그입니다: rows 또는 not rows |
column 선택 사항 | any |
columns 선택 사항 | 플래그입니다: columns 또는 not columns |
header 선택 사항 | 플래그: header 또는 not header |
as 선택 | type |
인수에 이름을 붙일 수 있습니다: ->cells(…, rows: …, column: …).
예시
<let name="prices" value="```csv
fruit,price
apple,3
plum,5
```" />
<!-- 'apple': the header line names each row's keys -->
<echo>{ $prices->cells(row: 0).fruit }</echo>
<!-- [3, 5]: the cells under the price header, as numbers -->
<echo>{ $prices->cells(column: 'price') }</echo>
<!-- 5: row 1 is plum, and its price is 5 -->
<echo>{ $prices->cells(row: 1, column: 'price') }</echo>
<!-- { fruit: ['apple', 'plum'], price: [3, 5] }: every column, keyed by its header -->
<echo>{ $prices->cells(columns) }</echo>
<let name="readings" value="```csv
387
942
945
```" />
<!-- 2274: every line is a number, so there's no header and every line is a row -->
<echo>{ $readings->cells(column: 0)->sum() }</echo>
<let name="puzzle" value="```csv
-903 -642 446
200 818
```" />
<!-- [-903, -642, 446]: spaces split the numbers on each line -->
<echo>{ $puzzle->cells(row: 0) }</echo>
<!-- [[-903, 200], [-642, 818], [446]]: the second row is too short for the third column -->
<echo>{ $puzzle->cells(columns) }</echo>$prices = ```csv
fruit,price
apple,3
plum,5
```
// 'apple': the header line names each row's keys
echo $prices->cells(row: 0).fruit
// [3, 5]: the cells under the price header, as numbers
echo $prices->cells(column: 'price')
// 5: row 1 is plum, and its price is 5
echo $prices->cells(row: 1, column: 'price')
// { fruit: ['apple', 'plum'], price: [3, 5] }: every column, keyed by its header
echo $prices->cells(columns)
$readings = ```csv
387
942
945
```
// 2274: every line is a number, so there's no header and every line is a row
echo $readings->cells(column: 0)->sum()
$puzzle = ```csv
-903 -642 446
200 818
```
// [-903, -642, 446]: spaces split the numbers on each line
echo $puzzle->cells(row: 0)
// [[-903, 200], [-642, 818], [446]]: the second row is too short for the third column
echo $puzzle->cells(columns)