note 76077 deleted from ref.array by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: phamphong_tn at yahoo dot com 

----

This is a code remove an other row of array
<?php
//$mang is an array, $id is index of row in array
function remove($mang,$id)
{
	$flag	=	false;
	$count	=	count($mang);
	$i	=	0;
	while ($flag!=true && $i<$count) {
		if ($i==$id) {
			unset($mang[$i]);
			$flag	=	true;
			$index	=	$i;
		}
		else {
			if ($temp) {
				array_push($temp,$mang[$i]);
			}
			else 
			{
				$temp	=	array($mang[$i]);
			}
		}
		$i++;
	}
	if ($flag) {
		while ($index<$count)
		{
			if ($temp) {
				array_push($temp,$mang[$index+1]);
			}
			else 
			{
				$temp	=	array($mang[$index+1]);
			}
			$index++;
		}
	}
	array_pop($temp);
	return $temp;
}

$arr	=	array(array("id"=>"1","name"=>"b"),array("id"=>"2","name"=>"d"));
array_push($arr,array("id"=>"3","name"=>"f"));
array_push($arr,array("id"=>4,"name"=>"g"));
$arr = remove($arr,2);
echo "<pre>";
print_r($arr);
?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.