Имеется массив $arr:
Array
(
[0] => Array
(
[0] => Array
(
[x] => 668
[y] => 693
[id] => 1143766
[type] => 45
[res] => Si
[neighbours] => Array
(
[0] => 43123377
[1] => 43975343
[2] => 43844283
[3] => 44040883
[4] => 44434103
)
)
[1] => Array
(
[x] => 658
[y] => 677
[id] => 1141366
[type] => 47
[res] => Si
[neighbours] => Array
(
[0] => 43451044
[1] => 43451049
)
)
[1] => Array
(
[0] => Array
(
[x] => 676
[y] => 677
[id] => 1141416
[type] => 58
[res] => Iw
[neighbours] => Array
(
[0] => 43975334
[1] => 43909792
)
)
[1] => Array
(
[x] => 696
[y] => 678
[id] => 1141463
[type] => 37
[res] => Iw
[neighbours] => Array
(
[0] => 45482664
[1] => 46072481
[2] => 45023916
[3] => 45679275
[4] => 46138025
[5] => 46138028
)
)
[2] => Array
(
[x] => 678
[y] => 695
[id] => 1143767
[type] => 45
[res] => Wi
[neighbours] => Array
(
[0] => 43844283
[1] => 43778741
[2] => 44040883
[3] => 44761776
)
)
[3] => Array
(
[x] => 676
[y] => 685
[id] => 1143783
[type] => 37
[res] => Ws
[neighbours] => Array
(
[0] => 43975334
[1] => 43975343
[2] => 44040883
[3] => 44761776
)
)
[2] => Array
(
[0] => Array
(
[x] => 657
[y] => 716
[id] => 1146107
[type] => 49
[res] => Wi
[neighbours] => Array
(
[0] => 42664649
[1] => 43582149
[2] => 42926801
)
)
[1] => Array
(
[x] => 655
[y] => 704
[id] => 1146108
[type] => 59
[res] => Ws
[neighbours] => Array
(
[0] => 42664634
[1] => 42926780
[2] => 43123394
[3] => 43582149
)
)
[2] => Array
(
[x] => 658
[y] => 706
[id] => 1146110
[type] => 40
[res] => Sw
[neighbours] => Array
(
[0] => 43647680
[1] => 42926780
[2] => 42664649
[3] => 43582149
)
)
Мне нужно произвести его слияние, но значения n могут быть различными... ($arr[n][n]).
На выходе нужно получить:
Array
(
[0] => Array
(
[x] => 668
[y] => 693
[id] => 1143766
[type] => 45
[res] => Si
[neighbours] => Array
(
[0] => 43123377
[1] => 43975343
[2] => 43844283
[3] => 44040883
[4] => 44434103
)
)
[1] => Array
(
[x] => 658
[y] => 677
[id] => 1141366
[type] => 47
[res] => Si
[neighbours] => Array
(
[0] => 43451044
[1] => 43451049
)
)
[2] => Array
(
[x] => 676
[y] => 677
[id] => 1141416
[type] => 58
[res] => Iw
[neighbours] => Array
(
[0] => 43975334
[1] => 43909792
)
)
[3] => Array
(
[x] => 696
[y] => 678
[id] => 1141463
[type] => 37
[res] => Iw
[neighbours] => Array
(
[0] => 45482664
[1] => 46072481
[2] => 45023916
[3] => 45679275
[4] => 46138025
[5] => 46138028
)
)
[4] => Array
(
[x] => 678
[y] => 695
[id] => 1143767
[type] => 45
[res] => Wi
[neighbours] => Array
(
[0] => 43844283
[1] => 43778741
[2] => 44040883
[3] => 44761776
)
)
[5] => Array
(
[x] => 676
[y] => 685
[id] => 1143783
[type] => 37
[res] => Ws
[neighbours] => Array
(
[0] => 43975334
[1] => 43975343
[2] => 44040883
[3] => 44761776
)
)
[6] => Array
(
[x] => 657
[y] => 716
[id] => 1146107
[type] => 49
[res] => Wi
[neighbours] => Array
(
[0] => 42664649
[1] => 43582149
[2] => 42926801
)
)
[7] => Array
(
[x] => 655
[y] => 704
[id] => 1146108
[type] => 59
[res] => Ws
[neighbours] => Array
(
[0] => 42664634
[1] => 42926780
[2] => 43123394
[3] => 43582149
)
)
[8] => Array
(
[x] => 658
[y] => 706
[id] => 1146110
[type] => 40
[res] => Sw
[neighbours] => Array
(
[0] => 43647680
[1] => 42926780
[2] => 42664649
[3] => 43582149
)
)
Делаю перебор массива
for($i=0; $i<=count($arr); $i++)
//Пытаюсь сделать слияние, но как это сделать в цикле не пойму...
$result = array_merge($arr[$i],???????);
print_r($result);
Спустя 34 минуты, 24 секунды (23.07.2012 - 11:08) pak написал(а):
у меня так получилось:
$m = array(..........)
foreach($m as $v)
{
foreach($v as $vv)
$arr[] = $vv;
}
print_r($arr);
Спустя 1 час, 28 минут, 33 секунды (23.07.2012 - 12:37) ArtemKrass написал(а):
Спасибо, теперь понял!
Спустя 51 минута, 57 секунд (23.07.2012 - 13:29) ArtemKrass написал(а):
А как теперь из полученного массива удалить [neighbours] со значениями?
Спустя 28 минут, 43 секунды (23.07.2012 - 13:57) dadli написал(а):
ArtemKrass
Цитата |
А как теперь из полученного массива удалить [neighbours] со значениями? |
$newArr = array();
foreach ($mas as $val) {
$arrVal = array();
foreach ($val as $k=>$v) {
if ($k != "neighbours") {
$arrVal[$k] = $v;
}
}
array_push($newArr,$arrVal);
}
// var_dump($newArr);
Спустя 15 минут, 34 секунды (23.07.2012 - 14:13) ArtemKrass написал(а):
Чет не работает... А unset по ключу нельзя?
Спустя 4 минуты, 25 секунд (23.07.2012 - 14:17) killer8080 написал(а):
Цитата (ArtemKrass @ 23.07.2012 - 14:13) |
Чет не работает... А unset по ключу нельзя? |
можно
Спустя 17 минут, 34 секунды (23.07.2012 - 14:35) ArtemKrass написал(а):
Сделал так:
Работает!
Просто хотелось в одном цикле все сделать...
Но не соображу как...
$arr1 = array();
foreach ($arr as $a)
{
unset($a['neighbours']);
$arr1[] = $a;
}
print_r ($arr1);
Работает!
Просто хотелось в одном цикле все сделать...
Но не соображу как...