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 8725603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:04:29+00:00 2026-06-13T08:04:29+00:00

So here’s what I want to do, I have a class and within SomeClass

  • 0

So here’s what I want to do, I have a class and within SomeClass, there’s a function consists of 2 variables, each has a numerical value. I want to return an array of the two variables which have dependencies in post data outside of SomeClass from a form that posts to itself.

<?php 
class SomeClass{

    private $someVar1;
    private $someVar2;

    public function setVars($var1,$var2) {  
       $this->someVar1 = $var1;
       $this->someVar2 = $var2;
    }

    function __construct() { 

    }

    function setFraction() {
          $sum['num'] = 140*pow($this->someVar1,0.75);
          $sum['den'] = $sum['num']/$this->someVar2;
          return $sum;
    }
}

if(isset($_POST['num'])){$num = preg_replace('/\D/', '', $_POST['num']);}
elseif(isset($_POST['den'])){$den = preg_replace('/\D/', '', $_POST['den']);}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

  Numerator:<input type="text" value="<?php if(isset($num)){echo $num;}?>" name="num" /><br />

  Denominator:<input type="text" value="<?php if(isset($den)){echo $den;}?>" name="den" /><br />

  <input type="submit" value="Go" name="Go"> 

</form>

<?php if(isset($num,$den)):
  $obj = new SomeClass();
  $obj->setVars($num,$den);
  $sum=$obj->setFraction();?>

  <pre>
    <?php print_r($obj->setFraction());?> 
  </pre>

  <ul>
    <?php foreach($sum as $val):?>
      <li><?php echo $val['num']?></li>
      <li><?php echo $val['den']?></li>
    <?php endforeach;?>
  </ul>

<?php endif;?>

When I run the script, post data for $num and $den is being sent and returned with setFraction(), however when I try to iterate through the array in a foreach loop, I don’t get any return data. I’m sure its something simple, I’ve tried it with a foreach loop and without with same results, any help would be excellent, thx.

EDIT:

<?php if(isset($num,$den)):
  $obj = new SomeClass();
  $obj->setVars($num,$den);
  $array = $obj->setFraction();?>

  <ul>
    <li><?php echo $array['num']?></li>
    <li><?php echo $array['den']?></li>
  </ul>

<?php endif;?>
  • 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-06-13T08:04:30+00:00Added an answer on June 13, 2026 at 8:04 am

    Store the returned data to some variable,and then iterate.

    //

    <?php if(isset($num,$den)):
      $obj = new SomeClass();
      $obj->setVars($num,$den);
      $array = $obj->setFraction();?>
    
    
      <ul>
        <?php foreach($array as $val):?>
          <li><?php echo $val['num']?></li>
          <li><?php echo $val['den']?></li>
        <?php endforeach;?>
      </ul>
    
    <?php endif;?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here are the tables I have: Table A which has entries with item and
here is a code: abstract class A { abstract public function add(); public function
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here is the code in a function I'm trying to revise. This example works
Basically, what I'm trying to create is a page of div tags, each has
Here's some sample HTML <style> .icon {display:none;} </style> <ul> <li>ABC <i id=abc class=icon>x</i></li> <li>DEF
Here are my functions: function dropmenu() { $(.dropdownitem).show('slow'); } function hidemenu() { $(.dropdownitem).hide('slow'); }
Here is the two scripts I have Script 1: <? include('config.php'); $json = $_POST['payload'];
Here is my AsyncTask. Getting exception in the AsyncTask.. private class GetCategories extends AsyncTask<String,

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.