채택완료

다차원 배열 받는 방법

2020-04-15 (수) 10:14:41 2,213

보낼 때 : friend.php

<input type="text" name="friend[]"  >

다 차원 배열로 보낼 때

받을 때 : friend_post.php

$friend=$_REQUEST['friend'];

다차원 배열로 받는 방법 구현 부탁드립니다.

|

답변 3개

채택된 답변
+20 포인트
2020-04-15 (수) 11:10:37

간단한 방법 3가지 소개합니다.

Copy
$data = implode('구분자', $_REQUEST['friend']);

$restore = explode('구분자', $data);


$data = serialize($_REQUEST['friend']);
$restore = unserialize($data);


$data = json_encode($_REQUEST['friend'], JSON_UNESCAPED_UNICODE); // PHP v5.4 미만은 뒤 옵션 제외
$restore = json_decode($data, 1);

* $_REQUEST는 특성을 이해하고 사용할 것.

An associative array that by default contains the contents of $_GET, $_POST and $_COOKIE.

$_SESSION()은 $ _GET, $ _POST의 대신 사용하고 있었습니다.

explode() 사용 방법은 알고 있었으나 

serialize(), unserialize()과

json_encode(), json_decode() 사용 방법

BiHon 님 덕에 배웠습니다.

감사합니다.

$friend 를 그냥 사용하시면 배열일텐데요...?

안되면..

Copy
$friend = $_REQUEST['friend[]'];

이렇게 해보시구..

Copy
print_r($_REQUEST);

이렇게 해서 확인해보실 수 있구요

답변을 작성하려면 로그인이 필요합니다.