我有一个存储在数据库中的json对象数组,它们实际上是Revolution滑块的设置。字符串从数据库表中检索,并分配到PHP变量是这样的:php&json对象搜索和值检查
$json = '[
{"sliderType": "standard","options": ["standard","carousel","hero"]},
{"sliderLayout": "auto","options": ["auto","fullwidth","fullscreen"]},
{"responsiveLevels": 4096},
{"gridwidth": 1200},
{"gridheight": 700},
{"autoHeight": "off","options": ["on","off"]},
{"minHeight": 0},
{"fullScreenOffsetContainer": ""},
{"fullScreenOffset": "0"},
{"delay": 9000},
{"waitForInit": false,"options": [true,false]},
{"disableProgressBar": "off","options": ["on","off"]},
{"startDelay": 0},
{"stopAfterLoops": -1},
{"stopAtSlide": -1},
{"viewPort": [
{"enable": false,"options": [true,false]},
{"outof": "wait","options": ["wait","pause"]},
{"visible_area": "60%"}
]
},
{"lazyType": "smart","options": ["full","smart","single","none"]},
{"dottedOverlay": "none","options": ["none","twoxtwo","threexthree","twoxtwowhite","threexthreewhite"]},
{"shadow": 0,"options": [0,1,2,3,4,5,6]},
{"spinner": "spinner0","options": ["off", "spinner0", "spinner1","spinner2", "spinner3", "spinner4", "spinner5"]},
{"debugMode": false,"options": [true,false]},
{"extensions": "extensions/"},
{"extensions_suffix": ".min.js"},
{"fallbacks": [
{"panZoomDisableOnMobile": "off","options": ["on","off"]},
{"nextSlideOnWindowFocus": "off","options": ["on","off"]},
{"disableFocusListener": true,"options": [true,false]}
]
},
{"parallax": [
{"type": "off","options": ["off","mouse","scroll","mouse+scroll"]},
{"levels": [10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85]},
{"origo": "enterpoint","options": ["slidercenter","enterpoint"]},
{"speed": 400},
{"bgparallax": "on","options": ["on","off"]},
{"disable_onmobile": "off","options": ["on","off"]}
]
},
{"carousel": [
{"horizontal_align": "center","options": ["left","right","center"]},
{"vertical_align": "center","options": ["top","bottom","center"]},
{"infinity": "on","options": ["on","off"]},
{"space": 0},
{"maxVisibleItems": 3},
{"stretch": "off","options": ["on","off"]},
{"fadeout": "off","options": ["on","off"]},
{"maxRotation": 0},
{"minScale": 0},
{"vary_fade": "off","options": ["on","off"]},
{"vary_rotation": "on","options": ["on","off"]},
{"vary_scale": "off","options": ["on","off"]},
{"border_radius": "0px"},
{"padding_top": 0},
{"padding_bottom": 0}
]
},
{"navigation": [
{"keyboardNavigation": "on", "options": ["on","off"]},
{"keyboard_direction": "horizontal", "options": ["horizontal","vertical"]},
{"mouseScrollNavigation": "off", "options": ["on","off"]},
{"onHoverStop": "on", "options": ["on","off"]},
{"touch": [
{"touchenabled": "on", "options": ["on", "off"]},
{"swipe_treshold": 75},
{"swipe_min_touches": 1},
{"drag_block_vertical": false, "options": [true, false]},
{"swipe_direction": "horizontal", "options": ["horizontal","vertical"]}
]
},
{"arrows": [
{"style": ""},
{"enable": false, "options": [true, false]},
{"rtl": false, "options": [true, false]},
{"hide_onmobile": false, "options": [true, false]},
{"hide_onleave": true, "options": [true, false]},
{"hide_delay": 200},
{"hide_delay_mobile": 1200},
{"hide_under": 0},
{"hide_over": 9999},
{"tmp": ""},
{"left": [
{"container": "slider", "options": ["slider","layergrid"]},
{"h_align": "left", "options": ["left","center","right"]},
{"v_align": "center", "otpions": ["top","center","bottom"]},
{"h_offset": 20},
{"v_offset": 0}
]
},
{"right": [
{"container": "slider", "options": ["slider","layergrid"]},
{"h_align": "left", "options": ["left","center","right"]},
{"v_align": "center", "otpions": ["top","center","bottom"]},
{"h_offset": 20},
{"v_offset": 0}
]
}
]
},
{"bullets": [
{"style": ""},
{"enable": false, "options": [true, false]},
{"rtl": false, "options": [true, false]},
{"container": "slider", "options": ["slider","layergrid"]},
{"hide_onmobile": false, "options": [true, false]},
{"hide_onleave": true, "options": [true, false]},
{"hide_delay": 200},
{"hide_delay_mobile": 1200},
{"hide_under": 0},
{"hide_over": 9999},
{"tmp": "<span class=\"tp-bullet-image\"></span><span class=\"tp-bullet-title\"></span>"},
{"direction": "horizontal", "options": ["horizontal","vertical"]},
{"space": 0},
{"h_align": "left", "options": ["left","center","right"]},
{"v_align": "center", "otpions": ["top","center","bottom"]},
{"h_offset": 20},
{"v_offset": 0}
]
},
{"thumbnails": [
{"style": ""},
{"enable": false, "options": [true, false]},
{"rtl": false, "options": [true, false]},
{"container": "slider", "options": ["slider","layergrid"]},
{"width": 100},
{"height": 50},
{"wrapper_padding": 2},
{"wrapper_opacity": 1},
{"wrapper_color": "#f5f5f5"},
{"visibleAmount": 5},
{"hide_onmobile": false, "options": [true, false]},
{"hide_onleave": true, "options": [true, false]},
{"hide_delay": 200},
{"hide_delay_mobile": 1200},
{"hide_under": 0},
{"hide_over": 9999},
{"tmp": "<span class=\"tp-thumb-image\"></span><span class=\"tp-thumb-title\"></span>"},
{"direction": "horizontal", "options": ["horizontal","vertical"]},
{"span": false, "options": [true, false]},
{"position": "inner", "options": ["inner","outer-left","outer-right","outer-bottom","outer-top"]},
{"space": 0},
{"h_align": "left", "options": ["left","center","right"]},
{"v_align": "center", "otpions": ["top","center","bottom"]},
{"h_offset": 20},
{"v_offset": 0}
]
},
{"tabs": [
{"style": ""},
{"enable": false, "options": [true, false]},
{"rtl": false, "options": [true, false]},
{"container": "slider", "options": ["slider","layergrid"]},
{"width": 100},
{"height": 50},
{"wrapper_padding": 2},
{"wrapper_opacity": 1},
{"wrapper_color": "#f5f5f5"},
{"visibleAmount": 5},
{"hide_onmobile": false, "options": [true, false]},
{"hide_onleave": true, "options": [true, false]},
{"hide_delay": 200},
{"hide_delay_mobile": 1200},
{"hide_under": 0},
{"hide_over": 9999},
{"tmp": "<span class=\"tp-thumb-image\"></span><span class=\"tp-thumb-title\"></span>"},
{"direction": "horizontal", "options": ["horizontal","vertical"]},
{"span": false, "options": [true, false]},
{"position": "inner", "options": ["inner","outer-left","outer-right","outer-bottom","outer-top"]},
{"space": 0},
{"h_align": "left", "options": ["left","center","right"]},
{"v_align": "center", "otpions": ["top","center","bottom"]},
{"h_offset": 20},
{"v_offset": 0}
]
}
]
}
]';
我可以把它转换成stdClass的对象或数组,需要什么的阵列。 我已经呈现了所有这些对象的页面,并使用了X-editable来根据需要更改值。所以,当x编辑插件单个对象发送新值的值的样子:
$_POST['name'] = 'navigation-arrows-left-container';
$_POST['value'] = 'customscontainer';
$_POST['pk'] = 1;
再次
我能够从这些数值构建一个JSON对象字符串:
$levels = explode('-', $_POST['name']);
$levels = array_reverse($levels);
$newjson = '';
foreach($levels AS $level){
if($newjson == ''){
$newjson = '"'.$level.'":"'.$_POST['value'].'"';
}else{
$newjson = '"'.$level.'":[{'.$newjson.'}]';
}
}
$newjson = '[{'.$newjson.'}]';
并将其转换为stdClass的对象或常规数组。 但我不知道如何测试新值是否与默认值相同,因为索引是不同的。我需要的是一个函数,它将检查已更改的键的值是否与默认对象中的值不同,如果不同,则返回true,如果与default相同,则返回false。
注意,为什么不使用'json_encode()'将数组转换成json而不是自己创建?似乎你留下了空间的错误,因为'json_encode()'将转换线返回和你不这样做.. – Rasclatt
它最初不是作为一个数组存在的。我按照革命滑块的文档手动创建了默认的json字符串,以了解可用的设置以及它们的默认值。我添加了对象“选项”,其中包含可用选项。因此,当我想要在管理中更改某些默认值并将它们呈现为特定滑块时,只有具有更改值的对象才会存储在变量中,因为不需要为滑块脚本呈现默认设置。 –