<html>
<head>
<title>PHP Functions</title>
</head>
<body>
<?php
function successfulCompaines($names_array, $rate)
{
$new_names = [];
$index = null;
$min = null;
foreach ($names_array as $i => $name)
{
$random_rate = rand(0,100);
if ($min == null)
{
$index = 0;
$min = $random_rate;
}
if ($random_rate <= $rate)
array_push($new_names, $name);
if ($random_rate < $min)
{
$index = $i;
$min = $random_rate;
}
}
return count($new_names) == 0 ? [$names_array[$index]]:$new_names;
}
$compaines = array("Lenovo","Huawei","Apple","Amazon","Microsoft","Abb","Netflex","Siemens","Samsung","Adidas","Uber","Dell","Hp","Walmart","Tesla","Google","Volvo","Toyota","Ibm","Shell");
$successRate = 0.5;
while(true)
{
$compaines = successfulCompaines($compaines, $successRate);
if (count($compaines) == 1)
{
echo 'Congrats for '. $compaines[0];
break;
}
$successRate /=2;
}
وصلت لهده المرحلة اريد ان يطبع البرنامج على الاقل شركتين او اكثر لانه يطبع لي شركة واجدة فقط