i am having problem swaping two element of array, can anyone help me....
I am getting following warrings, although it work correctly....I am idecating the line for error by ****
Warning: Undefined offset: 1 in D:\Inetpub\wwwroot\set\pratiktest\next.php on line 163
Warning: Undefined offset: 2 in D:\Inetpub\wwwroot\set\pratiktest\next.php on line 154
Warning: Undefined offset: 3 in D:\Inetpub\wwwroot\set\pratiktest\next.php on line 163
Warning: Undefined offset: 4 in D:\Inetpub\wwwroot\set\pratiktest\next.php on line 163
Warning: Undefined offset: 5 in D:\Inetpub\wwwroot\set\pratiktest\next.php on line 163
Warning: Undefined offset: 6 in D:\Inetpub\wwwroot\set\pratiktest\next.php on line 158
Code: Select all
function swap_twoelement_2Darray(&$array,$first_element, $second_element)
{
//make sure the first_element is smaller then the second_element
//or do a swap
if($first_element > $second_element)
{
$tempelement = $first_element;
$second_element = $first_element;
$first_element = $second_element;
}
//intialize conter to zero
$columncount=0;
//count number of colums in a array
while (list ($key,$value) = each($arrayї0]))
{
$columncount++;
}
//count number of rows in a array
$rowcount = sizeof ($array);
//check the dimensions to be swaped
for($rowCounter = 0;$rowCounter < $rowcount;$rowCounter++)
{
for($colCounter = 0; $colCounter < $columncount; $colCounter++)
{
if($first_element == $colCounter)
{
****$temp_arrayї$rowCounter]ї$first_element] = $arrayї$rowCounter]ї$first_element];
}
else if ($second_element == $colCounter)
{
**** $arrayї$rowCounter]ї$first_element] = $arrayї$rowCounter]ї$second_element];
$arrayї$rowCounter]ї$second_element] = $temp_arrayї$rowCounter]ї$first_element];
}
else
{
**** $arrayї$rowCounter]ї $colCounter] = $arrayї$rowCounter]ї $colCounter];
}
}
}
}