Core Function Remove

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> Remove( <array>, <start-id>, <end-id> ) </pre> === Description === Delete items from an array starting at a given location and stopping at a given location === Parameter...")
 
Line 5: Line 5:
 
=== Description ===
 
=== Description ===
  
Delete items from an array starting at a given location and stopping at a given location
+
Delete items from an array starting at a given location and stopping at a given location  
  
 
=== Parameters ===
 
=== Parameters ===
Line 12: Line 12:
  
 
The array to use.
 
The array to use.
 +
 +
==== start-id ====
 +
 +
Location to start deleting from.
 +
 +
==== end-id ====
 +
 +
Optional; Location to stop deleting at.
 +
 +
If this parameter is not given it then only the item at the start-id will be deleted and nothing else.
  
 
=== Return Value ===
 
=== Return Value ===
Line 25: Line 35:
 
=== Example ===
 
=== Example ===
  
 +
// Delete a single item
 +
<syntaxhighlight lang="sputnik">
 +
$array = array ( "One", "Two", "Three", "Four", "Five" );
 +
 +
Remove($array, 1);
 +
//unset($array[1]); // Alternative method
 +
 +
$i = 0;
 +
Foreach ( $array as $i )
 +
{
 +
println("Element ($i) is: " . $i);
 +
$i++;
 +
}
 +
</syntaxhighlight>
 +
 +
// Delete a range
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
 
$array = array ( "One", "Two", "Three", "Four", "Five" );
 
$array = array ( "One", "Two", "Three", "Four", "Five" );

Revision as of 06:35, 24 August 2013

Remove( <array>, <start-id>, <end-id> )

Contents

Description

Delete items from an array starting at a given location and stopping at a given location

Parameters

array

The array to use.

start-id

Location to start deleting from.

end-id

Optional; Location to stop deleting at.

If this parameter is not given it then only the item at the start-id will be deleted and nothing else.

Return Value

Success - Returns the amount of objects removed.

Failure - Returns 0.

Remarks

None

Example

// Delete a single item

$array = array ( "One", "Two", "Three", "Four", "Five" );
 
Remove($array, 1);
//unset($array[1]); // Alternative method
 
$i = 0;
Foreach ( $array as $i )
{
	println("Element ($i) is: " . $i);
	$i++;
}

// Delete a range

$array = array ( "One", "Two", "Three", "Four", "Five" );
 
Remove($array, 1, 2);
 
$i = 0;
Foreach ( $array as $i )
{
	println("Element ($i) is: " . $i);
	$i++;
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox