Array comparison and the corresponding relationship

Source: Internet
Author: User
Known quantity Group A:
$a = Array (0 = = Array (' Packageno ' = ' s2y140805025 ', ' type ' = ' ecs0-235 ', ' cust_no ' = ' + ' 12654    172 ', ' lotno ' = ' 4212 ',), 1 = = Array (' Packageno ' = ' s2y140805025 ', ' type ' = ' ecs0-235 ',  ' Cust_no ' = ' 12654172 ', ' lotno ' = ' 4214 ', ', ' 2 = = Array (' Packageno ' = ' SYS140804073 ', ' type ') = ' ecs0-235 ', ' cust_no ' = ' 12654172 ', ' lotno ' = ' 4212 ', ', ' 3 = = Array (' Packageno ' = ' SY ')    S140804073 ', ' type ' = ' ecs0-235 ', ' cust_no ' = ' 12654172 ', ' lotno ' = ' 4213 ', ', ' 4 = = Array (   ' Packageno ' = ' SYS140731064 ', ' type ' = ' ecs1-713 ', ' cust_no ' = ' 12657727 ', ' lotno ' = ' 4154 ', 5 = = Array (' Packageno ' = ' SYS140731064 ', ' type ' = ' ecs1-713 ', ' cust_no ' = ' 12657727 ', ' Lo TNO ' = ' 4210 ',), 6 = = Array (' Packageno ' = ' SYS140801090 ', ' type ' = ' ecs1-713 ', ' Cust_no ' =& Gt ' 12657727 ', ' Lotno ' = = ' 4200 ',), 7 = = Array (' Packageno ' = ' SYS140801090 ', ' type ' = ' ecs1-713 ', ' Cust_no ' =&gt ; ' 12657727 ', ' lotno ' = ' 4210 ',);


Have correspondence, for example Packageno s2y140805025 corresponds to Lotno 4212,4214 (type ecs0-235,cust_no is 12654172)

Also known as array B:
$b = Array (  0 = =   Array (    ' type ' = ' = ' ecs0-235 ',    ' cust_no ' = ' 12654172 ',    ' lotno ' = ' + ' 4211 ', '  ),  1 = =   Array (    ' type ' = ' ecs0-235 ',    ' cust_no ' = ' 12654172 ',    ' lotno ' = ') 4212 ',  ),  2 = =   Array (    ' type ' = ' ecs0-235 ',    ' cust_no ' = ' 12654172 ',    ' Lotno ' = ' 4213 ',  ),  3 = =   Array (    ' type ' = ' ecs0-235 ',    ' cust_no ' = ' 12654172 ',    ' Lotno ' = ' 4214 ',  ),  4 = =   Array (    ' type ' = ' ecs0-235 ',    ' cust_no ' = ' 12654172 ', c28/> ' lotno ' = ' 4216 ',  ),  5 = =   Array (    ' type ' = ' ecs1-713 ',    ' cust_no ' = ' = ') 12657727 ',    ' lotno ' = ' 4154 ',  ),  6 = =   Array (    ' type ' = ' ecs1-713 ',    ' cust_no ' = ' 12657727 ',    ' lotno ' = ' 4200 ',  ),  7 = =   Array (    ' type ' = ' = ' ecs1-713 ',    ' Cust_no ' = ' 12657727 ',    ' lotno ' = ' 4210 ',  );


Q: When the type and cust_no of arrays A and B are the same, the packageno corresponding to the Lotno in array A is contiguous in array B, and if not contiguous, the Packageno is displayed.

How do I handle it?


Reply to discussion (solution)

Why do you always have a strange need? Maybe there's something wrong with your process.
I'll show you the list.

$a = Array (0 = = Array (' Packageno ' = ' s2y140805025 ', ' type ' = ' ecs0-235 ', ' cust_no ' = ' + ' 12654    172 ', ' lotno ' = ' 4212 ',), 1 = = Array (' Packageno ' = ' s2y140805025 ', ' type ' = ' ecs0-235 ',  ' Cust_no ' = ' 12654172 ', ' lotno ' = ' 4214 ', ', ' 2 = = Array (' Packageno ' = ' SYS140804073 ', ' type ') = ' ecs0-235 ', ' cust_no ' = ' 12654172 ', ' lotno ' = ' 4212 ', ', ' 3 = = Array (' Packageno ' = ' SY ')    S140804073 ', ' type ' = ' ecs0-235 ', ' cust_no ' = ' 12654172 ', ' lotno ' = ' 4213 ', ', ' 4 = = Array (   ' Packageno ' = ' SYS140731064 ', ' type ' = ' ecs1-713 ', ' cust_no ' = ' 12657727 ', ' lotno ' = ' 4154 ', 5 = = Array (' Packageno ' = ' SYS140731064 ', ' type ' = ' ecs1-713 ', ' cust_no ' = ' 12657727 ', ' Lo TNO ' = ' 4210 ',), 6 = = Array (' Packageno ' = ' SYS140801090 ', ' type ' = ' ecs1-713 ', ' Cust_no ' =& Gt ' 12657727 ', ' Lotno ' = = ' 4200 ',), 7 = = Array (' Packageno ' = ' SYS140801090 ', ' type ' = ' ecs1-713 ', ' Cust_no ' =&gt ; ' 12657727 ', ' lotno ' = ' 4210 ', '), $b = Array (0 = = Array (' type ' = ' = ' ecs0-235 ', ' cust_no ' = ') 12654172 ', ' lotno ' = ' 4211 ',), 1 = = Array (' type ' = ' = ' ecs0-235 ', ' cust_no ' = ' 12654172 ', ' Lotno ' + ' 4212 ',), 2 = = Array (' type ' = ' ecs0-235 ', ' cust_no ' = ' 12654172 ', ' lotno ' = ' 4 213 ',), 3 = = Array (' type ' = ' = ' ecs0-235 ', ' cust_no ' = ' 12654172 ', ' lotno ' = ' 4214 ',), 4 =&   Gt Array (' type ' = ' ecs0-235 ', ' cust_no ' = ' 12654172 ', ' lotno ' = ' 4216 ',), 5 = = Array (' Typ E ' = ' ecs1-713 ', ' cust_no ' = ' 12657727 ', ' lotno ' = ' 4154 ', ', ' 6 = = Array (' type ' = ' = ' ecs1- 713 ', ' cust_no ' = ' 12657727 ', ' lotno ' = ' 4200 ', ', ' 7 = = Array (' type ' = ' ecs1-713 ', ' cust_ No ' = ' 12657727 ', ' lotno ' = ' 4210 ',), foreach ($a as $i = + $r) {if ($i = = 0) {echo preg_replace ("/\t/", "\t\t", join ("\    T ", Array_keys ($r)), 1);  echo "\t\tlotnos", Php_eol;  } echo join ("\ T", $r);  $t = Array (); foreach (Array_filter ($b, function ($v) use (& $r) {return $v [' type '] = = $r [' type '] && $v [' cust_no '] = = $r [' C  Ust_no '];  }) as $c) $t [] = $c [' Lotno ']; echo "\t\t".  Join (', ', $t); echo Php_eol;}
Packageno   type    cust_nolotnolotnoss2y140805025ecs0-2351265417242124211, 4212,4213,4214,4216s2y140805025ecs0-2351265417242144211, 4212,4213,4214,4216sys140804073ecs0-2351265417242124211, 4212,4213,4214,4216sys140804073ecs0-2351265417242134211, 4212,4213,4214,4216sys140731064ecs1-7131265772741544154,4200,4210sys140731064ecs1-7131265772742104154, 4200,4210sys140801090ecs1-7131265772742004154,4200,4210sys140801090ecs1-7131265772742104154,4200,4210

Why do you always have a strange need? Maybe there's something wrong with your process.
I'll show you the list.

Packageno   type    cust_nolotnolotnoss2y140805025ecs0-2351265417242124211, 4212,4213,4214,4216s2y140805025ecs0-2351265417242144211, 4212,4213,4214,4216sys140804073ecs0-2351265417242124211, 4212,4213,4214,4216sys140804073ecs0-2351265417242134211, 4212,4213,4214,4216sys140731064ecs1-7131265772741544154,4200,4210sys140731064ecs1-7131265772742104154, 4200,4210sys140801090ecs1-7131265772742004154,4200,4210sys140801090ecs1-7131265772742104154,4200,4210



It's possible. I ask Packageno if the corresponding lotno are arranged in the order of array B, like SYS140731064 corresponding Lotno 4154,4210, corresponding to the 4154,4200,4210 in the B array. There are 4200 between 4154 and 4210, so the SYS140731064 sort exception is identified and displayed.

Packageno   type    cust_nolotnolotnoss2y140805025ecs0-235126541724212, 42144211,4212,4213,4214,4216sys140804073ecs0-235126541724212, 42134211,4212,4213,4214,4216sys140731064ecs1-713126577274154, 42104154,4200,4210sys140801090ecs1-713126577274200,42104154,4200,4210



What if it turns out to be such a solution?

I didn't do the check, just output it directly to the Lotnos column.
Do you want to check it as you need it?

As for the print order, you just tune it.

I didn't do the check, just output it directly to the Lotnos column.
Do you want to check it as you need it?

As for the print order, you just tune it.



I don't understand how lotno and Lotnos compare. With the first package, how to determine the corresponding lotno in Lotnos discontinuous?

echo "\t\t". Join (', ', $t); is to print the Lotnos column.
The corresponding lotno in the B array are maintained in the array $t
Do you know if you're in a row?

echo "\t\t". Join (', ', $t); is to print the Lotnos column.
The corresponding lotno in the B array are maintained in the array $t
Do you know if you're in a row?



# code is not displayed after editing,
foreach (Array_filter ($b, function ($v) use (& $r) {
return $v [' type '] = = $r [' type '] && $v [' cust_no '] = = $r [' Cust_no '];
}) as $c) $t [] = $c [' Lotno '];
echo "\t\t". Join (', ', $t);

PHP version 5.2.5

echo "\t\t". Join (', ', $t); is to print the Lotnos column.
The corresponding lotno in the B array are maintained in the array $t
Do you know if you're in a row?



It seems that PHP 5.2.5 does not support usage of function use.
With regard to the use of sorting, it is not possible to understand the meaning of this sentence, but the trouble is to give an example.

  Array_filter ($b, function ($v) use (& $r) {    return $v [' type '] = = $r [' type '] && $v [' cust_no '] = = $r [' Cust_no '];  });

  Array_filter ($b, ' back '); {  function back ($v) {     global $r;     return $v [' type '] = = $r [' type '] && $v [' cust_no '] = = $r [' cust_no '];  }

....



A different form of asking,
Suppose array $ A, $a = array (  0 = ' 4154 ',  1 = ' 4210 ',);//Array $b, $b = Array (  0 = ' 4154 ',  1 = ' 4200 ',  2 = ' 4210 ',);


How can I tell if the array $ A is contiguous in the array $b?

What does that mean?

$a = Array (0 = ' 4154 ', 1 = ' 4210 ',); $b = Array (0 = ' 4154 ', 1 = ' 4200 ', 2 = ' 4210 ',); foreach ($ A as $v) {$c [] = Array_search ($v, $b);} for ($i =1; $i
  
  

What does that mean?

$a = Array (0 = ' 4154 ', 1 = ' 4210 ',); $b = Array (0 = ' 4154 ', 1 = ' 4200 ', 2 = ' 4210 ',); foreach ($ A as $v) {$c [] = Array_search ($v, $b);} for ($i =1; $i
     
    



But the situation should be discontinuous, but it will become continuous.
$a = Array (  0 = ' 4154 ',  1 = ' 4200 ',  2 = ' 4217 ',); $b = Array (  0 = ' 4154 ',  1 = ' 42 xx ',  2 = ' 4210 ',  3 = ' 4217 ',);//0, 1 consecutive, but 4217 the key value of the key and $b 4217 of the key value of unequal, so it is determined to be discontinuous.

What does that mean?



The value of the array $ A is continuously present in the array $b, which is determined as continuous//Example 1: (continuous) $a = array (4154,4200); $b = Array (4154,4200,4210); Example 2: (continuous) $a = Array (4200,4210), $b = Array (4154,4200,4210,4217);//Example 3: (discontinuous) $a = array (4200,4217); $b = Array ( 4154,4200,4210,4217);

The break exits the loop when the decision is not continuous, because it doesn't make any sense to compare it down.
What logic is your break outside of the conditional statement?

The break exits the loop when the decision is not continuous, because it doesn't make any sense to compare it down.
What logic is your break outside of the conditional statement?



Please ignore 13# to view 14# instructions.

function foo ($a, $b) {foreach ($a as $v) {$c [] = Array_search ($v, $b); } for ($i =1; $i 
      
        continuous continuous discontinuous 
       
  • 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.