• 03-07-2020, 18:52:11
    #1
    Merhaba hocalarım benim elimde alttaki gibi bir dizi var.

    Array
    (
    [0] => asametyildirim
    [1] => google
    [2] => asametyildirim
    [3] => google
    [4] => asametyildirim
    [5] => google
    [6] => asametyildirim
    [7] => google
    )
    Ben bu dizinin alttaki gibi olmasını istiyorum

    Array
    (
    [0] => asametyildirim.com
    [1] => google.com
    [2] => asametyildirim.com
    [3] => google.com
    [4] => asametyildirim.com
    [5] => google.com
    [6] => asametyildirim.com
    [7] => google.com
    )
    Bunun için şöyle bir kod yazdım
    for($i=0;$i<8;$i++){$dizi[$i]=$dizi[$i].".com";}
    lakin sonuç şu şekilde oluyor: (Sadece son satır istediğim gibi oluyor)

    Array
    (
    [0] => asametyildirim
    .com
    [1] => google
    .com
    [2] => asametyildirim
    .com
    [3] => google
    .com
    [4] => asametyildirim
    .com
    [5] => google
    .com
    [6] => asametyildirim
    .com
    [7] => google.com
    )
  • 03-07-2020, 18:54:26
    #2
    Array_map ile yapabilirsiniz sanirim
  • 03-07-2020, 19:00:36
    #3
    $dizi = array("asametyildirim","google");
    
    for($i=0;$i<count($dizi);$i++) {
    $dizi[$i] .= ".com";
    echo $dizi[$i];
        }
  • 03-07-2020, 19:01:38
    #4
    foreach ile açıp if ile bu ise bu olsun diyebilirsin isteğini karşılar bence.
  • 03-07-2020, 19:02:06
    #5
    <?php
    
    $sites = ['asametyildirim', 'google'];
    $sites = array_map(function($site){
    return "$site.com";
    }, $sites);
    print_r($sites);
  • 03-07-2020, 19:08:28
    #6
    for($i=0;$i<8;$i++){
    $dizi[$i] .=$dizi[$i].".com";
    }
  • 03-07-2020, 19:11:00
    #7
    WebKadir adlı üyeden alıntı: mesajı görüntüle
    Array_map ile yapabilirsiniz sanirim
    AtakanAtes adlı üyeden alıntı: mesajı görüntüle
    $dizi = array("asametyildirim","google");
    
    for($i=0;$i<count($dizi);$i++) {
    $dizi[$i] .= ".com";
    echo $dizi[$i];
    }
    Misafir adlı üyeden alıntı: mesajı görüntüle
    foreach ile açıp if ile bu ise bu olsun diyebilirsin isteğini karşılar bence.
    truser adlı üyeden alıntı: mesajı görüntüle
    <?php
    
    $sites = ['asametyildirim', 'google'];
    $sites = array_map(function($site){
    return "$site.com";
    }, $sites);
    print_r($sites);
    Evet bu kodlar çalışıyor, galiba benim dizimde sorun var. Diziyi .txt dosyasından alıyordum.

    Kullandığım kod:
    <?php
    $dosya = fopen('dosya.txt', 'r');
    $icerik = fread($dosya, filesize('dosya.txt'));
    
    $dizi = explode ("\n",$icerik);
    print_r($dizi);
    
    for($i=0;$i<count($dizi);$i++) {
    $dizi[$i] .= ".com";
    }
    echo '<pre>';
    print_r ($dizi);
    echo '</pre>';
    
    fclose($dosya);
    
    ?>
    dosya.txt içeriği:
    asametyildirim
    google
    asametyildirim
    google
    asametyildirim
    google
    asametyildirim
    google
  • 03-07-2020, 20:40:30
    #8
    $dosya = file_get_contents('dosya.txt');
    $exp = explode(PHP_EOL,$dosya);
    $sites = array();
    foreach($exp as $e){
        $sites[] = trim($e).'.com';
        //$sites[] = preg_replace('/\s+/','',$e);
    }
    print_r($sites);
    zaten cevabı vermişler, benim takıldığım nokta fopen fread kullanımınız, eğer okuduğunuz dosya mevcut php nin kullanabileceği ram boyutundan büyük değilse fopen kullanmanıza gerek yok, direkt file_get_contents ile çekebilirsiniz, tabi alışkanlığınız bu yöndeyse dicek bişey yok. kolaylıklar
  • 05-07-2020, 23:46:20
    #9
    array_map icersinde callback kullanip str_replace yapabilirsiniz.