note 76077 deleted from ref.array by felipe

From: Date: Sun, 30 Dec 2007 19:29:35 +0000
Subject: note 76077 deleted from ref.array by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-134531@lists.php.net to get a copy of this message
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); ?>

« previous php.notes (#134531) next »