copying multidimensional array
I have two function say responseA(); and responseB(); which returns a 2d
and 3d array respectively. I am trying to copy (1st and 2nd) column of
$responseA and (2nd and 3rd) column of $responseB to a new 3d array called
$response, the third column in the new array would be 'A' or 'B' depending
upon where it came from. Example:
$responseA = responseA(); $responseB = responseB();
$responseA[1,1371500801]; $responseB[111,1,1371340804];
$responseA[2,1371504502]; $responseB[131,2,1371760805];
$responseA[3,1371534503]; $responseB[121,3,1371130806];
the final array :
$response[1,1371500801,A];
$response[2,1371504502,A];
$response[3,1371534503,A];
$response[1,1371340804,B];
$response[2,1371760805,B];
$response[3,1371130806,B];
This is what I have done till now
for ($i=0;$i<count($responseA);$i++){
$response0[$i][0] = $myComments[$i][0];
$response0[$i][1] = $myComments[$i][1];
$response0[$i][2] = 'A';
}
for ($i=0;$i<count($responseB[0]);$i++){
$response1[$i][0] = $responseB[1][$i];
$response1[$i][1] = $responseB[2][$i];
$response0[$i][2] = 'B';
}
$response = array_merge($response0,$response1);
Could anyone here help me code the correct solution to create the response
array and sort this array according to the 2nd column (which is a
time-stamp)
Thank you so much.
No comments:
Post a Comment