PHP 에서 배열 선언시 array() 와 [] 의 차이점 > 개발

본문 바로가기
사이트 내 전체검색

개발

PHP 에서 배열 선언시 array() 와 [] 의 차이점

페이지 정보

profile_image
작성자 관리자 (112.♡.173.204)
댓글 0건 조회 1,417회 작성일 22-01-13 21:28

본문

## php 배열 선언

php 에서 배열 변수를 선언할 때 두가지 방법이 있다.

1. public $arr = array();
2. public $arr = [];

그럼 이 둘의 차이점이 뭘까?



## 차이점

PHP 5.4 에서 [] 가 추가되었기 때문에,
php < 5.4 에서는 array() 만 사용할 수 있다. [] 를 사용할 수 없다.


So for PHP >= 5.4 the short array syntax seems to be the de-facto standard. Only use array(), if you want your script to run on PHP <5.4.



## 사용법
```
<?php
$array = array(
    "foo" => "bar",
    "bar" => "foo",
);

// Using the short array syntax
$array = [
    "foo" => "bar",
    "bar" => "foo",
];
?>
```



## 출처
https://stackoverflow.com/questions/26651996/php-array-vs-in-method-and-variable-declaration
https://www.php.net/manual/en/language.types.array.php

추천0

댓글목록

등록된 댓글이 없습니다.

Total 386건 3 페이지
  • RSS
개발 목록
번호 제목 조회 추천 날짜
3463076006-15
3451701005-04
3441454003-11
3431911003-04
3421846002-21
3411992002-20
3402191002-18
3391719002-15
3381552002-13
3372015002-08
3361563002-08
3351588002-03
3341513001-31
3332581001-29
3321537001-28
열람중1418001-13
3301660012-23
3292305012-20
3284344005-19
3273572005-15

검색


사이트 정보

Copyright © Baragi.Net. All rights reserved.