Select an array based on the value of an internal key

1

I have the following array:

Array
(
  [ajax.js] => Array
    (
        [name] => ajax
        [fileName] => Web/js/App/ajax.js
        [file] => ajax.js
        [path] => Web/js/App
        [parent_path] => App
        [extension] => js
        [size] => 3.25
    )

  [functions.js] => Array
    (
        [name] => functions
        [fileName] => Web/js/App/functions.js
        [file] => functions.js
        [path] => Web/js/App
        [parent_path] => App
        [extension] => js
        [size] => 1.75
    )

  [jquery.js] => Array
    (
        [name] => jquery
        [fileName] => Web/js/jquery.js
        [file] => jquery.js
        [path] => Web/js
        [parent_path] => js
        [extension] => js
        [size] => 81.66
    )
)

How do I select the "parent array" based on some of the internal keys?

For example:

$myArray = array();

$myArray = $arrayAcima[]['App']

print($myArray);

Prints:

Array(
      [0] => ajax.js,
      [1] => functions.js
)

Is there a function that does this?

    
asked by anonymous 13.03.2014 / 14:27

2 answers

3

I think what you can do is something like:

function getParentArrays($parentPath, $arrayToSearch = array()) {
    $parentArrays = array();
    foreach ($arrayToSearch as $key => $value) {
        if ($value['parent_path'] === $parentPath) {
            $parentArrays[] = $key;
        }
    }
    return $parentArrays;
}
    
13.03.2014 / 14:43
0
<?php
$pais = array();

function obter_pais($filho, $chave, $identificador)
{
    global $pais;

    if (in_array($identificador, $filho))
    {
        $pais[] = $chave;
    }
}
array_walk($array, 'obter_pais', 'App');

print_r($pais);
    
13.03.2014 / 23:53