Merhaba arkadaşlar elimde sorumun sonuna eklediğim gibi bir dizi bulunmakta.Bu diziyi 2 seviyeli bir kategori olarak düşünebilirsiniz."parent" alanı üst kategorinin "idnumber" alanını işaret etmekte.Ancak ben "parent" alanının dizinin index numarası olmasını istiyorum.Örnek vermek gerekirse.

[131] => Array
    (
        [idnumber] => 171
        [name] => 9f146bfd1b1aa02612b95a0ae7b52f13
        [parent] => 21
    )

Bu dizimize ait üst array veya üst kategori;

[15] => Array
    (
        [idnumber] => 21
        [name] => 175d60205b36459d75d1cdda406f1ea4
        [parent] => 0
    )

Benim istediğim ise

[131] => Array ( [idnumber] => 171 [name] => 9f146bfd1b1aa02612b95a0ae7b52f13 [parent] => 15 )

Buraya kadar nispeten basit ancak problem bazı "idnumber" alanlarının aynı olması bu alanlar "parent" alanı 0 olanlar ile olmayanlar arasındaki çakışma.Bu gibi çakışmalar az olmasına rağmen diziyi tekrar düzenlerken problem yaşamaktayım.Problemi 3 foreach ile çözdüm ancak oldukça çok performans kaybı yaşadım.Daha verimli bir şekilde düzenlemek için önerileriniz nelerdir.

Array
(
    [0] => Array
        (
            [idnumber] => 433
            [name] => a2c8925220b6b1b0da3973396c0cd108
            [parent] => 0
        )

    [1] => Array
        (
            [idnumber] => 325
            [name] => e88e9c4a57d198c09c73e80b3ea3c6b4
            [parent] => 0
        )

    [2] => Array
        (
            [idnumber] => 327
            [name] => 844d3ef5110b9e64ea1f4cd4b90ca132
            [parent] => 0
        )

    [3] => Array
        (
            [idnumber] => 7758
            [name] => d1dfc50dedfe4ea1b7a149099a80e10c
            [parent] => 0
        )

    [4] => Array
        (
            [idnumber] => 328
            [name] => 8017101ae9cb183f0c2c574d439ecda8
            [parent] => 0
        )

    [5] => Array
        (
            [idnumber] => 331
            [name] => 49891f391525284e73a1675716d8e1e4
            [parent] => 0
        )

    [6] => Array
        (
            [idnumber] => 414
            [name] => 3e89cf3b3c688deab39cb60e5d1521af
            [parent] => 0
        )

    [7] => Array
        (
            [idnumber] => 7946
            [name] => c0833a1d36ae2be7f52a4f50466295ed
            [parent] => 0
        )

    [8] => Array
        (
            [idnumber] => 329
            [name] => 02186c71a6253223965a9ee70d2ed17f
            [parent] => 0
        )

    [9] => Array
        (
            [idnumber] => 19
            [name] => ecdf84f60437910c099f200be25cedf1
            [parent] => 0
        )

    [10] => Array
        (
            [idnumber] => 18
            [name] => f75e2a70527c6719cd2f21539036b4e2
            [parent] => 0
        )

    [11] => Array
        (
            [idnumber] => 415
            [name] => 21d7865f2427d65a664c10d38d24ea13
            [parent] => 0
        )

    [12] => Array
        (
            [idnumber] => 330
            [name] => bf2ac8c506387b8a3ad974d3a1a295ce
            [parent] => 0
        )

    [13] => Array
        (
            [idnumber] => 20
            [name] => b978fb4cb0d58479345d900ad3ca34e7
            [parent] => 0
        )

    [14] => Array
        (
            [idnumber] => 7757
            [name] => 0f66b5b894361329c9bdc60dd5ea7c8b
            [parent] => 0
        )

    [15] => Array
        (
            [idnumber] => 21
            [name] => 175d60205b36459d75d1cdda406f1ea4
            [parent] => 0
        )

    [16] => Array
        (
            [idnumber] => 416
            [name] => eacf58667eeafd9490d473b774ebb462
            [parent] => 0
        )

    [17] => Array
        (
            [idnumber] => 7756
            [name] => 9b84269ace836d2a320f8f3be3c5ea6a
            [parent] => 0
        )

    [18] => Array
        (
            [idnumber] => 7771
            [name] => 4f0cd7825aab84d0377f9e307bba2d71
            [parent] => 0
        )

    [19] => Array
        (
            [idnumber] => 23
            [name] => 9bfe6f10ea30411732eed8541639563f
            [parent] => 0
        )

    [20] => Array
        (
            [idnumber] => 429
            [name] => df3ef7626f9b0455d67443435c4e6dba
            [parent] => 0
        )

    [21] => Array
        (
            [idnumber] => 7890
            [name] => 15395b205bad7f3e36fc8b3b72746ab5
            [parent] => 0
        )

    [22] => Array
        (
            [idnumber] => 425
            [name] => 137220b2d62975d283b924a0ddd248c1
            [parent] => 0
        )

    [23] => Array
        (
            [idnumber] => 7
            [name] => 0e45a0ab15c868d9bc5d725968304076
            [parent] => 19
        )

    [24] => Array
        (
            [idnumber] => 8
            [name] => a8c99d65bb9395c6f744f12eb94fb119
            [parent] => 19
        )

    [25] => Array
        (
            [idnumber] => 9
            [name] => 3b84f212132ea63b3df46860a7b62af6
            [parent] => 19
        )

    [26] => Array
        (
            [idnumber] => 11
            [name] => 499a5ea53bb8f922740d6283b32e7c67
            [parent] => 19
        )

    [27] => Array
        (
            [idnumber] => 13
            [name] => 10d25ee7bc5439423a2cf1295c4a18c9
            [parent] => 19
        )

    [28] => Array
        (
            [idnumber] => 15
            [name] => 264b7390eabe5d84067da472c90b704d
            [parent] => 19
        )

    [29] => Array
        (
            [idnumber] => 17
            [name] => cf6ddee29dbbfa041bc1277abbee5fca
            [parent] => 19
        )

    [30] => Array
        (
            [idnumber] => 18
            [name] => 475e6246dbf5aa4774cfb6aed1f223a3
            [parent] => 19
        )

    [31] => Array
        (
            [idnumber] => 22
            [name] => d0c8be2ee968af2bd217946dc8d79cf5
            [parent] => 19
        )

    [32] => Array
        (
            [idnumber] => 23
            [name] => fbebe6735e37bf5afd82a178f694d823
            [parent] => 19
        )

    [33] => Array
        (
            [idnumber] => 24
            [name] => e93361e02cd866344592d85afa5eb0af
            [parent] => 19
        )

    [34] => Array
        (
            [idnumber] => 26
            [name] => e4368046a74c7366c3d7a34920950bd1
            [parent] => 18
        )

    [35] => Array
        (
            [idnumber] => 28
            [name] => e75118e2e9d35179ecde9d8d280af51a
            [parent] => 18
        )

    [36] => Array
        (
            [idnumber] => 29
            [name] => 7847fd5077032fc77651e4cea53b099e
            [parent] => 18
        )

    [37] => Array
        (
            [idnumber] => 30
            [name] => 11778423bba90c851a250b1e9f71386b
            [parent] => 18
        )

    [38] => Array
        (
            [idnumber] => 31
            [name] => 8558d19657e99ef6a71aaf6134a57355
            [parent] => 18
        )

    [39] => Array
        (
            [idnumber] => 32
            [name] => 58654b22b577ac46bce4c61ef40d10ca
            [parent] => 18
        )

    [40] => Array
        (
            [idnumber] => 33
            [name] => e7270a938e053eaff3c5fe9984174999
            [parent] => 18
        )

    [41] => Array
        (
            [idnumber] => 34
            [name] => 271da6055ffe18f43dbab615f2422692
            [parent] => 18
        )

    [42] => Array
        (
            [idnumber] => 35
            [name] => eedf03bea676eac48d8cd4e13645e0de
            [parent] => 18
        )

    [43] => Array
        (
            [idnumber] => 36
            [name] => f657ceca7ab3f19f170ac179eb2e7e92
            [parent] => 18
        )

    [44] => Array
        (
            [idnumber] => 38
            [name] => e5230a6a7239418050bd4cc47c3614ec
            [parent] => 18
        )

    [45] => Array
        (
            [idnumber] => 39
            [name] => 2531e2c5bd76ac0461740fbde55c3634
            [parent] => 18
        )

    [46] => Array
        (
            [idnumber] => 40
            [name] => 780b7625a5ec2e03730450a4f5e24b39
            [parent] => 18
        )

    [47] => Array
        (
            [idnumber] => 41
            [name] => 55d0234fcff0040ae944b4d3b7045737
            [parent] => 18
        )

    [48] => Array
        (
            [idnumber] => 42
            [name] => d627049101522353b8e611d2bbcd47e6
            [parent] => 18
        )

    [49] => Array
        (
            [idnumber] => 43
            [name] => 872facaf721796e97c5e0df6e4d5b93a
            [parent] => 18
        )

    [50] => Array
        (
            [idnumber] => 44
            [name] => bcd8ed29ca9fc66b12ffd8dab96bed1d
            [parent] => 18
        )

    [51] => Array
        (
            [idnumber] => 45
            [name] => 72d76372f293df54d9456434fea25149
            [parent] => 18
        )

    [52] => Array
        (
            [idnumber] => 46
            [name] => 692a547fb6fd4a143f8e3c9408f9f6e2
            [parent] => 20
        )

    [53] => Array
        (
            [idnumber] => 47
            [name] => 9ec462c2ad644aebe49d158f78358fd1
            [parent] => 20
        )

    [54] => Array
        (
            [idnumber] => 48
            [name] => 342875df8a48b77010f5781d89b1af27
            [parent] => 20
        )

    [55] => Array
        (
            [idnumber] => 49
            [name] => 33aba60927eea35fab311b23fc0a1bf4
            [parent] => 20
        )

    [56] => Array
        (
            [idnumber] => 50
            [name] => c4f64881b971c47195130f4c7d697b3e
            [parent] => 20
        )

    [57] => Array
        (
            [idnumber] => 51
            [name] => 50df2fe48c2e53f4f216e4f266439cf3
            [parent] => 20
        )

    [58] => Array
        (
            [idnumber] => 52
            [name] => b597f5537c334713fb944907eeb2d05a
            [parent] => 20
        )

    [59] => Array
        (
            [idnumber] => 53
            [name] => d2067bc65317ed97c201ce2795af04ea
            [parent] => 20
        )

    [60] => Array
        (
            [idnumber] => 54
            [name] => f15f125c54390c968b1821a5afee7605
            [parent] => 20
        )

    [61] => Array
        (
            [idnumber] => 67
            [name] => 39bb4be6f7e30a7631b2fd025bc91f16
            [parent] => 21
        )

    [62] => Array
        (
            [idnumber] => 69
            [name] => 76793afd574e5d76829dd86b05e73e1a
            [parent] => 416
        )

    [63] => Array
        (
            [idnumber] => 70
            [name] => b2eefd8e37aa3306790651eeb1ae265a
            [parent] => 416
        )

    [64] => Array
        (
            [idnumber] => 71
            [name] => dbfd24078ce6c3b41d907e1e9af44009
            [parent] => 416
        )

    [65] => Array
        (
            [idnumber] => 74
            [name] => 9fc683d522580cd8a9f7589eee17aee8
            [parent] => 415
        )

    [66] => Array
        (
            [idnumber] => 77
            [name] => 0c8a52ec9b69c16a278142f5f1778b23
            [parent] => 414
        )

    [67] => Array
        (
            [idnumber] => 84
            [name] => ed13d27194a7c8ec10ae78f7edde7e78
            [parent] => 328
        )

    [68] => Array
        (
            [idnumber] => 85
            [name] => 296acae6743ae09f3056be5be2d7853c
            [parent] => 328
        )

    [69] => Array
        (
            [idnumber] => 86
            [name] => a8051e9837a4425f036b84f836f34149
            [parent] => 329
        )

    [70] => Array
        (
            [idnumber] => 87
            [name] => 29b7e255580b7a4be94145f5ef42923e
            [parent] => 329
        )

    [71] => Array
        (
            [idnumber] => 88
            [name] => 5278e04859e872d7bcd9e65cda9c0f56
            [parent] => 329
        )

    [72] => Array
        (
            [idnumber] => 89
            [name] => 140e465803de655a5b05cee052ca85e1
            [parent] => 329
        )

    [73] => Array
        (
            [idnumber] => 92
            [name] => 99b48a46e92397167254a6247e0b4953
            [parent] => 329
        )

    [74] => Array
        (
            [idnumber] => 93
            [name] => aac30240cf45fbfb6fb85c98516ba655
            [parent] => 329
        )

    [75] => Array
        (
            [idnumber] => 94
            [name] => ae65dc3cd4877ba2f45e4f1957d8ac59
            [parent] => 7946
        )

    [76] => Array
        (
            [idnumber] => 95
            [name] => 0ba7c97a63925f1cca6be8ed9be62090
            [parent] => 7946
        )
)

soruldu: 26 Haz '13, 04:45

xuma's gravatar image

xuma
26111
cevap kabul oranı: 100%

değiştirildi: 13 Tem '13, 01:07

%C3%B6zcanacar's gravatar image

özcanacar ♦♦
17.2k59183183


Tekrar merhaba arkadaşlar cevabı başka bir yerden buldum.Güzel düşünülmüş bir cevap;

// create a list of the indexes's for each idnumber
$convert_list=array(); // initialise array
reset($data); // pointer to start
while(list($index,$datum)=each($data)) // loop through data
{
    $idnumber=$datum['idnumber'];
    // if idnumber already exists, then dont log it again
    if(!isset($convert_list[$idnumber])) $convert_list[$idnumber]=$index;
}

// create a NEW parent with the index of the entry with that idnumber
reset($data); // pointer to start
while(list($index,$datum)=each($data)) // loop through data
{
    $parent=$datum['parent'];
    if($parent==0)
    {
        // no parent
        $data[$index]['new_parent']=0;
    }
    else
    {
        // check if idnumber actually exists, otherwise say its not found
        if(isset($convert_list[$parent]))
        {
            $data[$index]['new_parent']=$convert_list[$parent];
        }
        else
        {
            $data[$index]['new_parent']='not found';
        }
    }
}
permanent link

cevaplandı: 26 Haz '13, 05:55

xuma's gravatar image

xuma
26111
cevap kabul oranı: 100%

Cevabınız
toggle preview

Bu soruyu takip et

E-Posta üzerinden:

Üyelik girişi yaptıktan sonra abonelik işlemlerini yapabilirsiniz

RSS üzerinden:

Cevaplar

Cevaplar ve Yorumlar

Yazı Formatlama

  • *italic* ya da _italic_
  • **bold** ya da __bold__
  • link:[text](http://url.com/ "başlık")
  • resim?![alt text](/path/img.jpg "başlık")
  • liste: 1. Foo 2. Bar
  • temel HTML etiketleri de kullanılabilir

Bu sorunun etiketleri:

×168
×13

Soruldu: 26 Haz '13, 04:45

Görüntüleme: 605 kez

Son güncelleme: 13 Tem '13, 01:07

powered by BitNami OSQA