Format my JSON string into an
    ordered list in PHP

后端 未结 5 948
抹茶落季
抹茶落季 2021-01-29 14:48

I\'m working on a simple CMS for a pet project. I currently have a JSON string that contains a list of page ID\'s and Parent page ID\'s for a menu structure.

I want to n

5条回答
  •  梦如初夏
    2021-01-29 15:25

    I have found that i have to fix or simplify almost every of the functions above. So here i came with something simple and working, still recursion.

    function build_list($array) {
        $list = '
      '; foreach($array as $key => $value) { if (is_array($value)) { $list .= "$key: " . build_list($value); } else { $list .= "
    • $key: $value
    • "; } } $list .= '
    '; return $list; } build_list(json_encode($json_string),true);

提交回复
热议问题