array 배열 문의드립니다.
"parcelInfoList": [{
"amount": 0.1, # 상품 개당 가격
"name": "iPhone", # 상품명
"originCountry": "SG", #상품 원산지
"quantity": 1, #상품 개수
"unit": "EA" #상품 단위
}
],
위 배열에 [] <- 형님들~~ 이 기호를 어떻게 감쌀수가 있을까요?
예시)
제품명 선언 요소, 다중 요소 지원, "[]" 기호를 사용한 요소 이름, ";" 기호를 사용하여 분할하는 다중 요소, 입력 형식: "[{"brand":"test "},{"specifications":"test2"},{"mode":"L3"},{"Manufacturer Identification Code":"test2"}]"
답변 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);
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인