如何获取父项是数组中项目的所有结果


How to get all the results where parent is an item from an array

我有一个由父名称组成的数组,我想得到任何名称都是父级的所有结果。这是我的代码。我无法获得父级等于区域数组中名称的名称列表。

这是我的完整代码。

<?php
$functionname = 'core_course_get_categories';
$username = array('key' => 'name', 'value' => '2016');
$params = array('criteria' => array($username));
$server_url = 'localhost/moodle' . '/webservice/rest/server.php' . '?wstoken=' . '9cdaccf3a7ad2f0f94922ccfd02559f4' . '&wsfunction=' . $functionname;
$rest_format = 'json';
require_once('curl.inc');
$curl = new curl;
$rest_format = ($rest_format == 'json') ? '&moodlewsrestformat=' . $rest_format : '';
$resp = $curl->post($server_url . $rest_format, $params);
$res = json_decode($resp);
// drupal_set_message('<pre>'. dpm($res) .'</pre>');
$district = array();
$Ctsc = array();
$School = array();
$Grade = array();
$parent = array();
foreach ($res as $r) {
    $a = $r->parent;
    $c = $r->name;
    if ($a == 0) {
        $b = $r->id;
        var_export($b);
    }
}
foreach ($res as $r) {
    if ($r->parent == $b) {
        //$dist=$r->name;
        $district[] = $r->name;
    }
}    
$Ctsc[] = $r->description;
$School[] = $r->sortorder;
$Grade[] = $r->depth;
foreach ($res as $r) {        
    $q = $r->name;
    if (in_array($q['parent'], $district)) {
        $Ctsc[] = $q->name;
        dpm($Ctsc);
    }
    if ($Ctsc['parent'] == $district) {
        dpm($Ctsc);
    }
}

in_array()的用法是错误的。

而不是

if(in_array($q['parent'] == $district)){ ... }

if(in_array($q['parent'], $district)){ ... }