Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Truncate an Array
How To Truncate an Array? - PHP Script Tips - PHP Built-in Functions for Arrays
✍: FYIcenter.com
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, 8335👍, 0💬
Popular Posts:
What will happen in these three cases? if (a=0) { //somecode } if (a==0) { //do something } if (a===...
How To Enter a New Row into a Table Interactively? - Oracle DBA FAQ - Introduction to Oracle SQL Dev...
How do we host a WCF service in IIS? Note: - The best to know how to host a WCF in IIS is by doing a...
Can Two Forms Be Nested? - XHTML 1.0 Tutorials - Understanding Forms and Input Fields Can two forms ...
What Is C Language? The C programming language is a standardized programming language developed in t...