我有三组三组,我想在算法上做到这一点:
treeset1
treeset2
treeset3
treeset4
这样做的最佳方式是什么? 一个非常简单的例子:
if(isset($_POST['email'])) {
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
// You can replace all of this with HTML.... dont forget that
// as long as you keep the echo $error part
die();
}
function clean_phone_number($string) {
$string = str_replace(' ', '-', $string);
$string = preg_replace('/[^0-9\-]/', '', $string);
return preg_replace('/-+/', '-', $string);
}
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
function required_field($field,$field_name){
if($field == ""){
died($field_name. " is a required Field!");
}
}
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "mail1@example.com , mail2@example.com , mail3@example.com";
$email_subject = "Wood Engraving Services - Order Quote";
// validation expected data exists
$error_message = "";
//get fields, and check if they are filled
$project_name = $_POST['project_name'];
required_field($project_name,"Project Name");
$email_from = $_POST['email'];
required_field($email_from,"Email");
$phone_number = $_POST['phone_number'];
required_field($phone_number,"Phone Number");
$wood_type = $_POST['wood_type'];
required_field($wood_type,"Wood Type");
$size = $_POST['size'];
required_field($size,"Size");
$attachment_file_link = $_POST['attachment'];
$other_info = $_POST['other_info'];
required_field($other_info,"Additional Info");
转到treeset1,对其执行操作,如果完成,则删除treeset1,排序,下一个元素将变为treeset4(原来是treeset2),现在在treeset4上执行某些操作,未完成,不要删除treesert4,再次排序,接下来是treeset3,做一些事情,完成,完成treeset3,再次排序,再次使用treeset4进行排序,在treeset4上做一些事情......
最佳做法是什么?我有排序功能。一旦到达最后一个元素,算法就会停止,并且无法删除任何元素。
答案 0 :(得分:0)
我想通过迭代器做到这一点。在每个循环之后,我使用迭代器并调用next()。它解决了我的问题。