Work with complex arrays of other programmers in PHP

I support an OO PHP application that loads everything in $ this array. When I do a var dump on $ this to find out how to access the value, I get dozens of pages of output. Hunting the array elements that I need is very time consuming.

For example, if I want to find where the territory of the client is stored, I need to find out the hierarchy of the array using print_r or var_dump and look at [ edit: and search]] on the output until I find out the path.

for example: $ this-> Billing-> Cst-> Record ['Territory']

Is there a better way to do this, or some tools / methods that I can use. For example, is there a quick way to find the path to the variable ['Territory'] throughout the array directly?

+3
source share
4 answers

Krumo is a var_dump graphical tool that makes navigation easier. Check out the Examples section on the project page.

For searching in multidimensional arrays, this SO question can help you.

+4
source

Perhaps you could do ctr + F in the output instead of looking at it?

Just start with ctr + F: "Client", "Territory" and all other names related to what you are looking for.

+1
source
function findInTree($var, $words) {
    $words = explode(' ', strtolower($words));
    $path = array();
    $depth = 0;
    $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($var), RecursiveIteratorIterator::SELF_FIRST);
    foreach ($iterator as $key => $value) {
        if ($iterator->getDepth() < $depth) {
            unset($path[$depth]);
        }
        $depth = $iterator->getDepth();
        $path[$depth] = $key;

        if (is_string($key) && in_array(strtolower($key), $words)) {
            echo '<pre>', implode(' -&gt; ', $path), '</pre>';
        }
    }
}

findInTree($this, 'Customer Territory');

.

+1
0

Source: https://habr.com/ru/post/1773509/


All Articles