Write a PHP program to create a new array using the first n strings from a given array of strings. (n>=1 and <=length of the array)
- برمجة بي اتش بي
- 2021-09-08
- mhanasmh00489829403
الأجوبة
<?php
function test($arr_str, $n)
{
$new_array = [sizeof($arr_str)];
for ($i = 0; $i < $n; $i++)
{
$new_array[$i] = $arr_str[$i];
}
return $new_array;
}
$result = test(["a", "b", "bb", "c", "ccc"], 3);
echo implode(" ",$result);
Sample Output:
a b bb
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال