Answer the question
In order to leave comments, you need to log in
How to do if the function returns false, then output a string?
Hello. Tell me how to do it, if the function returns false, then display the line: “Incorrect array”, if there is a number, then display: “The sum of the array elements is ...”.
$test = [5,'5',5];
function summ_array ($array){
$rezult = 0;
if (is_array($array)){
foreach ($array as $value){
if (is_numeric($value)){
$rezult = $rezult + $value;
}
elseif(func_num_args($value) == 0){
echo 'Neobhodimy parametry';}
else {
$rezult = false;
}
}
} else {
$rezult = false;
}
return $rezult;
}
echo summ_array($test);
$summaN = [];
echo "Сумма элементов массива равна" .summ_array($summaN);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question