ARRAY WORD SWAPING IN PHP
ARRAY:
An array is a special variable, which can hold more than one value at a time. If you
have a list of items (a list of names, for example), storing values , variable ...etc...,
ISSET:
The isset() function is an inbuilt function in PHP which checks whether a variable is
set and is not NULL.
<?php
if(isset($_GET['submit'])){
$from=$_GET['arrayfrom'];
$to=$_GET['arrayto'];
$array =array('ravi','ravi2','ravi3','ravi4','ravi5','ravi6','ravi7','ravi8','ravi9','ravi10','ravi11');
$array = array_move_elem($array, $from, $to); // Move element OR swapping
print_r($array);
}
?>
<html>
<form action="" method="get">
<label>arrayfrom<input type="text" name="arrayfrom"></input></label>
<label>arrayto<input type="text" name="arrayto"></input></label>
<input type="submit" name="submit" value="submit"></input>
</form>
</html>
<?php
function array_move_elem($array, $from, $to) {
if ($from == $to)
{
return $array;
}
$c = count($array);
if (($c > $from) and ($c > $to))
{
if ($from < $to)
{
$f = $array[$from];
for ($i = $from; $i < $to; $i++)
{
$array[$i] = $array[$i+1];
}
$array[$to] = $f;
} else {
$f = $array[$from];
for ($i = $from; $i > $to; $i--) {
$array[$i] = $array[$i-1];
}
$array[$to] = $f;
}
}
return $array;
}?>