= $skip){ if (!is_array($variable)){ if ($length > 1){ /* Disabled splicing of arrays since I can't figure how to do it right now. Will have to look at this later. The splicing of single variables still works fine. for ($y = $skip; $y < ($length+$skip); $y++){ if ($y < count($array)){ $replaced[count($replaced)] = $array[$y]; } } $array[$skip] = $variable; break; */ }else{ $replaced[count($replaced)] = $array[$x]; $array[$x] = $variable; break; } }elseif (is_array($variable)){ for ($y = $skip; $y <= $length; $y++){ $replaced[count($replaced)] = $array[$y]; $array[$y] = $array[($skip+$length)]; } for ($y = (count($array)-$length); $y < count($array); $y++){ unset($array[$y]); } $temp = $array; unset($array); for ($y = ($skip-1); $y >= 0; $y--){ $array[$y] = $temp[$y]; } for ($y = $skip; $y < count($variable); $y++){ $array[count($array)] = $variable[$y]; } for ($y = $skip; $y < count($temp); $y++){ $array[count($array)] = $temp[$y]; } } } } return $replaced; } # ######################################################################## ################### Sort unique functions ########################## # # Sorts an array into unique elements. If there are arrays # within the top level array, only the second level arrays # are sorted. Any arrays beyond the second level are not sorted. # if $type is specified as 'nocase' then all elements are # sorted case-insensitive. # function sort_unique(&$data, $type = ""){ if (!is_array($data)){ settype($data,"array"); } if (count($data) < 1){ print "Array is empty!
\n"; return; } if (isset($temp)){ unset($temp); } $count = 0; for ($x = 0; $x < count($data); $x++){ if (is_array($data[$x])){ sort_unique_sub(&$data[$x], $type); $count++; } } if ($count == 0){ sort_unique_sub(&$data, $type); } } function sort_unique_sub ($data, $type = ""){ if (isset($temp)){ unset($temp); } if ($type == "nocase"){ for ($x = 0; $x < count($data); $x++){ $data[$x] = strtolower($data[$x]); } } sort($data); for ($x = 0; $x < count($data); $x++){ if ($data[$x] != $data[$x+1]){ $temp[sizeof($temp)] = $data[$x]; } } unset ($data); for ($x = 0; $x < count($temp); $x++){ $data[$x] = $temp[$x]; } } # #################################################################### ################ Truncate array function ######################### # # This function will remove all elements from the specified # element to the end of array. # function truncate_array(&$data, $element){ if (!is_array($data)){ settype($data,"array"); } if (count($data) < 1){ print "Array is empty!
\n"; return; } if (!$element){ print "Must specify array element!
\n"; return; } if (count($data) < $element){ $num = count($data); print "Array only has $num elements!
\n"; return; } for ($x = count($data); $x >= 1; $x--){ if ($x >= $element){ unset($data[$x-1]); } } } # ################################################################ ############### Get array range function ####################### # # This function will take an array and a range of elements. It # then alters the array so that only the range of elements # specified exist in the array. # function get_array_range(&$data, $range = ""){ if (!is_array($data)){ settype($data,"array"); } if (count($data) < 1){ print "Array is empty!
\n"; return; } if (!$range){ print "No range specified!
\n"; return; } list($start,$end) = split("-",$range); if ($start > $end){ $temp = $start; $start = $end; $end = $temp; } if ($end > count($data)){ $num = count($data); print "Array only has $num elements!
\n"; return; } if (isset($temp)){ unset($temp); } for ($x = 1; $x <= count($data); $x++){ if ($x >= $start && $x <= $end){ $temp[sizeof($temp)] = $data[$x-1]; } } unset($data); $data = $temp; unset($temp); } # ################################################################# ?>