Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6130557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:52:20+00:00 2026-05-23T16:52:20+00:00

Can someone fix my functions? First, how can I go about getting the mean

  • 0

Can someone fix my functions?

First, how can I go about getting the mean from my numbers that are used in the sum function? What varaible can I use to divide the numbers if I don’t know how many numbers will be used?

Second, why isn’t my find replace function working? When I run the string with the ‘bad’ words, i get this (i just entered ugly):

array(1) { [0]=> string(4) "nice" }

I want the whole string returned with just the bad words replaced…

also, even tho its in there its not returning the length of the string and the number of words in the string! Grr…Pretty frustrated so i would be very grateful for any help…

File one: (to get the return of the functions)

    <?php
    require('myfunctions.php');
    if($_POST) {
    $result = phptest($_POST['input']);
    if ($result === false) {
    echo 'No rude words were found.';
    } else {
    var_dump($result);
    }
    }
    ?>

    <?php
    echo "<br/> Sum function:".sum(1,2,3,4)."<br/>";
    echo "Average function:".mean(1,2,3,4)."<br/>";
    ?>

    <form action="" method="post">
    <input name="input" type="text" size="20" maxlength="20" />
    <input name="submit" type="submit" value="submit" />
    </form>

myfunctions:

    <?php
    function sum()
    {
    $sum = 0;
    for ($i=0; $i<func_num_args(); $i++) $sum+= func_get_arg($i);
    return $sum;
    }

    ?>
    <?php
    function phptest($input) {
    $search = array('ugly', 'rude');
    $replace = array('nice', 'sweet');
    $output = str_ireplace($search, $replace, $input, $replace_count);
    if ($replace_count === 0) {
    return false;
    } else {
    return explode(' ', $output);
    }
    }

    ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:52:21+00:00Added an answer on May 23, 2026 at 4:52 pm

    No need to reinvent the wheel. Take advantage of PHP native functions, like array_sum() in combination with your func_* functions.

    function sum() {
      return array_sum(func_get_args());
    }
    
    function avg() {
      $args = func_num_args();
    
      if ($args == 0) {
        return 0;
      }
    
      return array_sum(func_get_args()) / $args;
    }
    

    As far as your phptest() function, see the comment by Glass Robot.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone show me how to fix the width of a column in a
Can someone explain this result to me. The first test succeeds but the second
I've run into a really strange bug, that I'm hoping someone can explain. I
Looking at the last demo for the .change() jQuery function. Can someone explain to
Can someone help me fix my code I am trying to put null in
Can someone show me how to implement a recursive lambda expression to traverse a
Can someone explain the mechanics of a jump table and why is would be
Can someone give an example of a good time to actually use unsafe and
Can someone describe what a symbol table is within the context of C and
Can someone explain to me the advantages of using an IOC container over simply

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.