Example #1
0
 /**
  * rcube_shared.inc: array_keys_recursive()
  */
 function test_array_keys_recursive()
 {
     $input = array('one' => array('two' => array('three' => array(), 'four' => 'something')), 'five' => 'test');
     $result = array_keys_recursive($input);
     $input_str = 'one,two,three,four,five';
     $result_str = implode(',', $result);
     $this->assertEquals($input_str, $result_str, "Invalid array_keys_recursive() result");
 }
Example #2
0
/**
 * Get all keys from array (recursive).
 *
 * @param array $array  Input array
 *
 * @return array List of array keys
 */
function array_keys_recursive($array)
{
    $keys = array();
    if (!empty($array) && is_array($array)) {
        foreach ($array as $key => $child) {
            $keys[] = $key;
            foreach (array_keys_recursive($child) as $val) {
                $keys[] = $val;
            }
        }
    }
    return $keys;
}
Example #3
0
 /**
  * THREAD=REFS sorting implementation
  *
  * @param  array $tree  Thread tree array (message identifiers as keys)
  * @param  array $index Array of sorted message identifiers
  * @return array   Array of sorted roots messages
  * @access private
  */
 private function _sort_thread_refs($tree, $index)
 {
     if (empty($tree)) {
         return array();
     }
     $index = array_combine(array_values($index), $index);
     // assign roots
     foreach ($tree as $idx => $val) {
         $index[$idx] = $idx;
         if (!empty($val)) {
             $idx_arr = array_keys_recursive($tree[$idx]);
             foreach ($idx_arr as $subidx) {
                 $index[$subidx] = $idx;
             }
         }
     }
     $index = array_values($index);
     // create sorted array of roots
     $msg_index = array();
     if ($this->sort_order != 'DESC') {
         foreach ($index as $idx) {
             if (!isset($msg_index[$idx])) {
                 $msg_index[$idx] = $idx;
             }
         }
         $msg_index = array_values($msg_index);
     } else {
         for ($x = count($index) - 1; $x >= 0; $x--) {
             if (!isset($msg_index[$index[$x]])) {
                 $msg_index[$index[$x]] = $index[$x];
             }
         }
         $msg_index = array_reverse($msg_index);
     }
     return $msg_index;
 }