PHP Diziler - tüm Değerler için bir dize ekleme

0 Cevap php

What is the best way to add a specific value or values to an array? Kinda hard to explain, but this should help:

<?php
$myarray = array("test", "test2", "test3");
$myarray = array_addstuff($myarray, " ");
var_dump($myarray);
?>

Hangi çıkışlar:

array(3) {
  [0]=>
  string(5) " test"
  [1]=>
  string(6) " test2"
  [2]=>
  string(6) " test3"
}

Bunu gibi pek yapabilirdi:

function array_addstuff($a, $i) {
    foreach ($a as &$e)
        $e = $i . $e;
    return $a;
}

Daha hızlı bir şekilde, ya da bu fonksiyon ise yerleşik varsa ama ben merak ediyorum.

0 Cevap