Jump to content
alexarpad2003

countif

Recommended Posts

Poate m-am exprimat gresit, sunt si obosit.

Asa ca dau un exemplu mai concret.


<?php
$b=('4 3 4');
$c=explode(' ',$;

$a=array_sum($c) / count($c);
echo $a;
?>

Imi afiseaza 4.6667

Dar daca am asa


<?php
$b=('4 3 4 -');
$c=explode(' ',$;

$a=array_sum($c) / count($c);
echo $a;
?>

Imi afiseaza 2.75 pentru ca imi vede 4 valori si se imparte la 4, iar eu nu vreau asta. Vreau sa pun o conditie pentru a nu-mi numerota valorea '-' daca mi-o gaseste in array. Deci sa imparta tot la 3.

Link to comment
Share on other sites

sau asa


<?php
$result = array();
$b=('4 3 4 -');
$c=explode(' ',$;
for($i=0;$i<count($c);$i++) { // initiam o bucla for, pentru a verifica fiecare element al array-ului
if(is_numeric($c[$i])) { // daca elementu e numeric
$result[] = $c[$i]; // il trecem in alt array numit $result
}
}
$a=array_sum($result) / count($result);
echo $a;
?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...