Tools, FAQ, Tutorials:
Truncating an Array in PHP
How To Truncate an Array in PHP?
✍: 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 )
⇒ Joining Array Values into a Single String in PHP
⇐ Padding an Array with a Given Value in PHP
2017-01-05, 2835🔥, 0💬
Popular Posts:
What Is session_register() in PHP? session_register() is old function that registers global variable...
How to create Hello-3.1.epub with WinRAR? I have all required files to create Hello-3.1.epub. To cre...
How to use .NET CLR Types in Azure API Policy? By default, Azure imports many basic .NET CLR (Common...
How to create a navigation file like navigation.xhtml for an EPUB 3.0 book? At least one navigation ...
How to convert a JSON text string to an XML document with PHP language? Currently, there is no built...