我已经从Nestable获得序列化,但我不知道如何编写 php 代码更新我的数据库,如wordpress:
$data = '[{"id":1},{"id":2,"children":[{"id":3},{"id":4},{"id":5,"children":[{"id":6},{"id":7},{"id":8}]},{"id":9},{"id":10}]},{"id":11},{"id":12}]';
function extract_value($value,$order=0){
if(is_array($value)){
foreach($value as $k => $v){
echo "UPDATE vod_page_menu SET ordering = '$order', parent_id = '$v' WHERE id = '$v'; <br/>";
extract_value($v,$order+1);
}
}
}
$json = json_decode($data,true);
extract_value($json);