Я пытаюсь объединить индекс массива, такой как
011,021,031, 012,022,032, 013,023,033, 014,024,034.
$temp = array();
foreach($samplearray as $key => $val){
foreach($val as $key1 => $val1){
//what should logic here
}
}
массив образцов
$samplearray = array ( "AA" => array ( 0 => array ( "created by" => "011",
"date" => "12-03-14",
"time" => "12.00 pm"),
1 => array ( "created by" => "012",
"date" => "12-03-14",
"time" => "12.00 pm"),
2 => array ( "created by" => "013",
"date" => "12-03-14",
"time" => "12.00 pm"),
3 => array ( "created by" => "014",
"date" => "12-03-14",
"time" => "12.00 pm")
),
"BB" => array ( 0 => array ( "created by" => "021",
"date" => "12-03-14",
"time" => "12.00 pm"),
1 => array ( "created by" => "022",
"date" => "12-03-14",
"time" => "12.00 pm"),
2 => array ( "created by" => "023",
"date" => "12-03-14",
"time" => "12.00 pm"),
3 => array ( "created by" => "024",
"date" => "12-03-14",
"time" => "12.00 pm")
),
"CC" => array ( 0 => array ( "created by" => "031",
"date" => "12-03-14",
"time" => "12.00 pm"),
1 => array ( "created by" => "032",
"date" => "12-03-14",
"time" => "12.00 pm"),
2 => array ( "created by" => "033",
"date" => "12-03-14",
"time" => "12.00 pm"),
3 => array ( "created by" => "034",
"date" => "12-03-14",
"time" => "12.00 pm")
)
);
Требуемый выход
$newArray = array ( 0 => array ( "created by" => "011",
"date" => "12-03-14",
"time" => "12.00 pm"),
1 => array ( "created by" => "021",
"date" => "12-03-14",
"time" => "12.00 pm"),
2 => array ( "created by" => "031",
"date" => "12-03-14",
"time" => "12.00 pm"),
3 => array ( "created by" => "012",
"date" => "12-03-14",
"time" => "12.00 pm"),
4 => array ( "created by" => "022",
"date" => "12-03-14",
"time" => "12.00 pm"),
5 => array ( "created by" => "032",
"date" => "12-03-14",
"time" => "12.00 pm"),
6 => array ( "created by" => "013",
"date" => "12-03-14",
"time" => "12.00 pm"),
7 => array ( "created by" => "023",
"date" => "12-03-14",
"time" => "12.00 pm"),
8 => array ( "created by" => "033",
"date" => "12-03-14",
"time" => "12.00 pm"),
9 => array ( "created by" => "014",
"date" => "12-03-14",
"time" => "12.00 pm"),
10 => array ( "created by" => "024",
"date" => "12-03-14",
"time" => "12.00 pm"),
11 => array ( "created by" => "034",
"date" => "12-03-14",
"time" => "12.00 pm"),
);
На самом деле это довольно просто. Подсказка уже есть в заголовке. array_merge()
:
$newArray = array();
foreach ($samplearray as $key => $batch) {
$newArray = array_merge($newArray, $batch);
}
Чтобы следовать этому специальному формату, вы можете сдвигать их каждый раз, пока $samplearray
заканчивается.
Пример:
$newArray = array();
while(true) {
foreach ($samplearray as $key => &$batch) {
$newArray[] = array_shift($batch); // shift each batch
}
if(empty($batch)) { // if it runs out, stop!
break;
}
}
попробуй этот код
$temp = array();
foreach($samplearray as $key => $val){
foreach($val as $key1 => $val1){
$temp[] = $val1;
}