How To Truncate an Array
How To Truncate an Array? - PHP Script Tips - PHP Built-in Functions for Arrays
If you want to remove a chunk of values from an array, you can use the array_splice($array, $offset, $length) function. $offset defines the starting position of the chunk to be removed. If $offset is positive, it is counted from the beginning of the array. If negative, it is counted from the end of the array. array_splice() also returns the removed chunk of values. Here is a PHP script on how to use array_splice():
<?php $array = array("Zero"=>"PHP", "One"=>"Perl", "Two"=>"Java"); $removed = array_splice($array, -2, 2); print("Remaining chunk:\n"); print_r($array); print("\n"); print("Removed chunk:\n"); print_r($removed); ?>
This script will print:
Remaining chunk: Array ( [Zero] => PHP ) Removed chunk: Array ( [One] => Perl [Two] => Java )
2007-04-21, 5635👍, 0💬
1. What is normalization. 2. Difference between procedure and functions. 3. Oracle 9i Vs 10g. 4. how...
How is the MVC design pattern used in Struts framework? In the MVS design pattern, there 3 component...
How did you implement UML in your project ? PART II Implementation phase / Coding phase (Class diagr...
Can Java object be locked down for exclusive use by a given thread? Yes. You can lock an object by p...
Once I have developed the COM wrapper do I have to still register the COM in registry? Yes.