테스트 사이트 - 개발 중인 베타 버전입니다

array 배열 문의드립니다.

왕대인 1개월 전 조회 156

    "parcelInfoList": [{

            "amount": 0.1, # 상품 개당 가격

            "name": "iPhone", # 상품명

            "originCountry": "SG",  #상품 원산지

            "quantity": 1, #상품 개수

            "unit": "EA" #상품 단위

        }

    ],

 

위 배열에 [] <- 형님들~~ 이 기호를 어떻게 감쌀수가 있을까요?

 

예시)

제품명 선언 요소, 다중 요소 지원, "[]" 기호를 사용한 요소 이름, ";" 기호를 사용하여 분할하는 다중 요소, 입력 형식: "[{"brand":"test "},{"specifications":"test2"},{"mode":"L3"},{"Manufacturer Identification Code":"test2"}]"

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

답변 1개

웅푸
1개월 전

"parcelInfoList": [
  {
    "amount": 0.1,
    "name": "iPhone",
    "originCountry": "SG",
    "quantity": 1,
    "unit": "EA",
    "productDetails": [{ "brand": "Apple" },{ "specifications": "128GB" },{ "mode": "Pro" },{ "Manufacturer Identification Code": "A1234" }
    ]
  }
]

or

$productDetails = "brand:Apple;specifications:128GB;mode:Pro;Manufacturer Identification Code:A1234";

$items = explode(";", $productDetails);
$result = [];

foreach ($items as $item) {
    list($key, $value) = explode(":", $item, 2);
    $result[] = [trim($key) => trim($value)];
}

echo json_encode($result, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);

 

로그인 후 평가할 수 있습니다

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

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

로그인