사용자가 큰 JSON 파일의 데이터를 업데이트 할 수 있도록 양식을 설정하려고합니다. 사용자가 원하는 '이벤트'를 잡고 편집 할 수있는 양식이 있습니다. 제출을 클릭하면 전체 JSON 파일을 배열로 가져 오는 스크립트로 데이터를 보냅니다. 거기에서 그 배열을 검색하고 편집 된 '이벤트'와 동일한 ID를 가진 하위 배열의 인덱스를 찾으려면 스크립트가 필요합니다. 따라서 사용자가 "William Bradford born"라는 항목을 편집 한 경우 "american-ccincore-1411541230"ID와 일치하는 스크립트가 필요하며 해당 하위 배열의 색인은 0을 반환합니다.PHP : 주어진 값을 기반으로 다차원 배열의 배열 색인 찾기
[
{
"id" : "american",
"title" : "A Timeline of American Literature",
"description" : "LENGTHY DESCRIPTIVE TEXT",
"initial_zoom" : "50",
"focus_date" : "1650-01-01 00:00:00",
"size_importance" : "true",
"timezone" : "-06:00",
"min_zoom" : "20",
"max_zoom" : "80",
"image_lane_height" : "50",
"display_zoom_level" : "1",
"tags" : {
"Puritan" : "0",
"Enlightenment" : "0",
"Romantic" : "0",
"Transcendental" : "0",
"Dark Romantic": "0",
"African American": "0",
"American Indian": "0",
"International" : "0"
},
"legend": [
{
"title": "Author event",
"icon": "star_red.png"
},
{
"title": "Publication event",
"icon": "square_blue.png"
},
{
"title": "Historical event",
"icon": "triangle_green.png"
}
],
"events": [
{
"id": "american-ccincore-1411541230",
"title": "William Bradford born",
"description": "LENGTHY DESCRIPTIVE TEXT",
"tags": "Puritan",
"startdate": "1950-03- 00:00:00",
"enddate": "1657-05- 00:00:00",
"importance": "50",
"date_display": "year",
"link": "",
"image": "https://www.csustan.edu/sites/default/files/ENGLISH/reuben/pal/chap1/bradford.gif",
"icon": "star_red.png",
"span_color": "#f66"
}, {
"id": "american-mforkner-1411364607",
"title": "Church Mission Society",
"description": "LENGTHY DESCRIPTIVE TEXT",
"tags": "",
"startdate": "1799-01-01 00:00:00",
"enddate": "1799-01-01 00:00:00",
"importance": "50",
"date_display": "year",
"link": "",
"image": "http://webarchive.cms-uk.org/_images/tnsaies1.jpg",
"icon": ".png",
"span_color": "#ccc"
}
]
}
]
12 개 정도의 게시물에 제안 된 스크립트를 적용하려고 시도했지만이 특정 상황에서는 작동하지 않습니다. 어떤 조언을 주셔서 감사합니다.
변경이'위해 var_dump()'당신이 코드를 작업중인 곳 사람들이 데이터 구조 – TML
를 다시 입력 할 필요가 없습니다? – Ghost
데이터가 사용 가능한 상태에 이르렀으므로 다음 명백한 질문은 "편집 이벤트에서 어떤 데이터가 전송 되는지요?"입니다. 예를 들어 수정 된 값만 얻은 경우 원래 값이 무엇인지 찾으려면 어떻게해야합니까? – TML