Implementation of a piece of algorithm and nested judgment

Source: Internet
Author: User
For more information, see the implementation of an algorithm. nested judgment involves two arrays: $ a [0], $ a [1], $ a [2], and $ B [0]. $ B [1], $ B [2] starts to judge the block size first. if it is true, all judgments are ended, jump to another & nbsp; code & nbsp; brick; if it is false, judge the size of $ a [1] and $ B [1]. if it is tr, ask you for an algorithm implementation, nested judgment
Suppose there are two arrays $ a [0], $ a [1], $ a [2], and $ B [0], $ B [1], $ B [2]

// ============= Determine the start of a block
First, judge the size of $ a [0] and $ B [0]. if it is true, end all judgments and jump to another code brick;
If it is false
Determine the size of $ a [1] and $ B [1]. if it is true, end all judgments and jump to another code brick;
If it is false
Determine the size of $ a [2] and $ B [2], and end the judgment.
// ============== Judge the block end
Another code brick;

Is it necessary to use continuous if nesting?
If not, how should we implement it?


------ Solution --------------------
Method functions are managed using arrays, and arrays are judged cyclically. functions are selected based on subscripts.

function f1(){
echo 1;
}
function f2(){
echo 2;
}
$fns=Array(f1,f2);
$a= Array(3,2);
$b=Array(2,3);
foreach($a as $k => $v )
if( $v > $b[$k] ) $fns[$k]();

------ Solution --------------------
For ($ I = 0; $ I $ K = 1;
If ($ a [$ I] ==$ B [$ I]) break;
$ K = 0;
}
If ($ k ){
Another code brick;
}
------ Solution --------------------
You feel like a post that was asked not long ago to judge the submitted content one by one, but that is to end the judgment when false is met.

Another idea:

function comp($n, $m)
{
if ($n ==$m) return True;
else return False;
}
$c = array_map("comp", $a, $b);
if (count(array_intersect($c, array(True))) > 0){
another code brick;
}
?>

However, if you want to finish all the units, it may not match your question.
However, you can keep the reference, which is useful when all others must be judged.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.