예제 #1
0
파일: coreutils.php 프로젝트: rocksyne/wyf
/**
 * A re-implementation of the array splice function.
 * 
 * @param type $input
 * @param type $start
 * @param type $length
 * @param type $replacement
 * @return type 
 */
function array_splic(&$input, $start, $length = 0, $replacement = null)
{
    $keys = array_Keys($input);
    $values = array_Values($input);
    if ($replacement !== null) {
        $replacement = (array) $replacement;
        $rKeys = array_Keys($replacement);
        $rValues = array_Values($replacement);
    }
    // optional arguments
    if ($replacement !== null) {
        array_Splice($keys, $start, $length, $rKeys);
        array_Splice($values, $start, $length, $rValues);
    } else {
        array_Splice($keys, $start, $length);
        array_Splice($values, $start, $length);
    }
    $input = array_Combine($keys, $values);
    return $input;
}
예제 #2
0
 public static function array_insert(&$original = array(), $insert = null, $position = 'after', $key = null, $sens = true)
 {
     if (!empty($insert)) {
         $after = $position == 'after' ? true : false;
         $insert = (array) $insert;
         $assoc = array_keys($insert) !== range(0, count($insert) - 1);
         $keep_keys = is_string($insert) || !$assoc || $sens;
         if (!empty($key) && array_key_exists($key, $original)) {
             $start = self::key_offset($original, $key);
             $start = $after ? $start + 1 : $start;
             if (!$keep_keys) {
                 array_Splice($original, $start, 0, $insert);
             } else {
                 $keys = array_Keys($original);
                 $values = array_Values($original);
                 $insert = (array) $insert;
                 $rKeys = array_Keys($insert);
                 $rValues = array_Values($insert);
                 array_Splice($keys, $start, 0, $rKeys);
                 array_Splice($values, $start, 0, $rValues);
                 $original = array_Combine($keys, $values);
             }
         } else {
             $original = $after ? array_merge($original, $insert) : array_merge($insert, $original);
         }
     }
 }