PHP7 배열 선언 코드

미랑 · 2021-11-03 16:01:07
기존 PHP5.4 이하 버전에서처럼 배열을 선언하면 오류가 남
따라서 수정된 내용으로 작성을 해야 함

const DEFAULT_ROLES = array('guy', 'development team');

The short syntax works too, as you'd expect:

const DEFAULT_ROLES = ['guy', 'development team'];

If you have PHP 7, you can finally use define(), just as you had first tried:

define('DEFAULT_ROLES', array('guy', 'development team'));


** 실제 적용 코드 **

// 2021.11.03
// PHP7에서는 배열변수 선언 필요
// 파일명 설정
// $filename = '';
define('filename', array('code', 'org', 'ext'));

if($user_filename == "")
{
$filename['code'] = date("Ymd") . "_" . date("His") . "_" . substr(md5(uniqid(rand())), 0, 5) . "." .  $extension; 
$filename['org'] = $_FILES[$fieldname]['name'];
$filename['ext'] = $extension;