İçeriğe geç

Dize oluşturma optimizasyonu (ARCH7071)

Anahtar php.performance.string-builder-optimization · Önem info · Kategori performance

Tek bir ifadede çok sayıda parçayı . ile derin zincirlemek okunması zor ve verimsizdir. Bunun yerine bir format dizesi veya implode() kullanın.

<?php
$line = $id . ' - ' . $name . ' (' . $age . ') ' . $city . ', ' . $country;
echo $line;
<?php
$line = sprintf('%d - %s (%d) %s, %s', $id, $name, $age, $city, $country);
echo $line;

Çok parçalı dize üretiminde sprintf() veya implode() kullanarak tek bir ifadede birleştirin.