S
S
sarkisssik2017-09-23 20:22:23
PHP
sarkisssik, 2017-09-23 20:22:23

How to do recursion?

Hello. I can’t figure out a bit with recursion, namely how to build it. There are properties (for example, number of rooms, type of housing, etc.) and there are their values. I need to collect references of these values ​​depending on the nesting of their properties.
For example (number of rooms -> housing type -> wall material):

1-roomatnie
1-room/vtorichka
1-room/vtorichka/kirpichnie
Maybe I created the table incorrectly, so I can't catch up.
e6e7918bb89248d487ac694b3a3fcf18.PNG

  1. n_category - number of the category to which the property belongs (apartments)
  2. value_properties - property value
  3. link - property link
  4. name - name
  5. n_prop - id - properties (number of rooms, type of housing, etc.)
  6. priority - does not carry any information at the moment
  7. parent - parent n_prop

This method turned out, I didn’t have the mind to finish ((
function get_data_dynamic_link($data,$parent=0){

    $tree = array();

    foreach ($data as $id=> $value) {    

        $tree[] = $value['link'];
        //$tree[] = $this->get_data_dynamic_link($data,$value['parent']);

    }

    return $tree;       
   }

Thanks for any advice.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Yanyshev, 2017-09-24
@villiwalla

Recursion is not needed to collect the url, just glue the array via implode with the separator / and get /cat/cat2/cat3 as the output, the order of the lines can be determined even when selecting through sort by parenr asc

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question