Write a PHP program to create a new string which is n (non-negative integer) copies of a given string

  • برمجة بي اتش بي

Write a PHP program to create a new string which is n (non-negative integer) copies of a given string

الأجوبة

<?php
function test($s, $n) 
{
    $result = "";
    for ($i = 0; $i < $n; $i++)
            {
                $result = $result.$s;
            }
            return $result;
 }


echo test("JS", 2)."\n";
echo test("JS", 3)."\n";
echo test("JS", 1)."\n";

Sample Output:

JSJS
JSJSJS
JS
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...