728x90
PHP는 배열을 사용하는 방법이 크게 두 가지가 있습니다.
PHP 배열 생성
><!DOCTYPE html>
<html>
<head>
<title>PHP 배열 생성</title>
</head>
<body>
<?php
class X {
//배열 생성 방법1.
var $cars = ['Volvo','BMW','Toyota'];
//배열 생성 방법2.
var $cellPhones = array('a' => "apple", "ss" => "SamSung");
function X(){
$this -> prop1 = 'ex1';
$this -> prop2 = 'ex2';
}
function greet() { echo 'Hello!';}
/*
function __construct(){
$this->greet(); // $this는 인스턴스를 의미
} */
}
$sample = new X;
var_dump($sample->cars);
echo "<br/>";
var_dump($sample->cellPhones);
?>
</body>
</html>
결과
728x90
'PHP' 카테고리의 다른 글
PHP mysqli_fetch_array의 이해 (2) | 2023.12.06 |
---|---|
PHP 세션 (2) | 2023.11.28 |