I am learning to program in php and I have a little problem.
I have two arrays:
Array A:
array(10){
[0]: string(10) "2012-08-01"
[1]: int 1
[2]: string(10) "2012-08-03"
[3]: int 1
[4]: string(10) "2012-08-07"
[5]: int 2
[6]: string(10) "2012-08-09"
[7]: int 2
[8]: string(10) "2012-08-27"
[9]: int 1
}
Array B:
array(4){
[0]: string(10) "2012-09-04"
[1]: string(10) "2012-09-06"
[2]: string(10) "2012-09-08"
[3]: string(10) "2012-09-10"
}
I want to check if the first element from Array A equals the first element from Array B, if it does then write second element (in this case 1) from array A to an new Array C (one dimensional) else don’t write anything in an array C and next check if element with index 2 from an array A equals second element [1]: string(10) "2012-09-06" from an array B if so the write fourth element ([3]: int 1) from an array A to an array C etc. so an array C would have int elements only.
If someone could help me out how to sort this out please I would be very happy
If you really need to do it this way, you could do something like the following:
However, a string-indexed array would probably be better for Array A. Use the following for the 3 examples below:
If Array A always contains more elements than Array B (or the same number):
If Array B always contains more elements than Array A (or the same number):
If it is possible that sometimes Array A is longer and sometimes Array B is longer:
Populating arrayC with zeros foreach entry in arrayA that does not have a match in arrayB: