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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T01:12:30+00:00 2026-05-12T01:12:30+00:00

I want to return a set of values from function till the point they

  • 0

I want to return a set of values from function till the point they exist….
for example….

function abc($i="3"){

    for($a=1;$a<=$i;$a++) {
        $name='t'.$i;
        $$name = "ae".$a;
    }
    //now i am returning values 
    return array($t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10);
    //but i only want to return $t1,$t2,$t3 depending on $i
}

Thanks….

@therefromhere
I am also creating an array in the loop , I’ll paste the original code so that you can understand it in a better way

function extracting_comments($table, $fields,$condition,$order,$limit){
        $query="SELECT ".$fields."
                FROM ".$table."
                WHERE ".$condition."
                ORDER BY ".$order."
                LIMIT ".$limit." ";
        if($stmt = $this->conn->prepare($query)) {
            $stmt->execute();
            $row = array_pad(array(), $stmt->field_count, '');
            $params = array();
                foreach($row as $k=>$v) {
                  $params[] = &$row[$k];
                  echo $params[0];
                }
            call_user_func_array(array($stmt,'bind_result'),$params);
            $i=0;
            while($stmt->fetch()) {
            $i++;
            $name='t'.$i;
            $$name = array();
            foreach ($row as $b=>$elem) {
            $atul[$b]=$row[$b];
            }
            $$name=$atul;
            }
            return array($t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10);
            $stmt->close();
        }

    }

now their are only 5 rows of data so their is no point returning $t6,$t7,$t8,$t9,$t10
and i want to fix it ,and i am calling the function using

$extract=extracting_comments($table, $fields,$condition,$order,$limit);

please help…thanks

  • 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-12T01:12:30+00:00Added an answer on May 12, 2026 at 1:12 am

    I believe this will help you. You have very complicated code with a lot of side effects and bug, you’d better to consider to redisgn it. Also putting statements after return will no have any effect, since it wouldn’t be invoked.

    function extracting_comments($table, $fields,$condition,$order,$limit){
                    $query="SELECT ".$fields."
                                    FROM ".$table."
                                    WHERE ".$condition."
                                    ORDER BY ".$order."
                                    LIMIT ".$limit." ";
                    if($stmt = $this->conn->prepare($query)) {
                            $stmt->execute();
                            $row = array_pad(array(), $stmt->field_count, '');
                            $params = array();
                                    foreach($row as $k=>$v) {
                                      $params[] = &$row[$k];
                                      echo $params[0];
                                    }
                            call_user_func_array(array($stmt,'bind_result'),$params);
                            $i=0;
                            $result = array();
                            while($stmt->fetch()) {
                            $i++;
                            foreach ($row as $b=>$elem) {
                            $atul[$b]=$row[$b];
                            }
                            $result[]=$atul;
                            }
                            $stmt->close();
                            return $result;
                    }
    
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When @RadioServiceGroup is set to NULL, I want to return all the records from
In my SWT Java app I often want to return information from inside a
For Example: Let's say that I want to return a view that displays a
I have the following code to return multiple values from pl/python: CREATE TYPE named_value
I want to return StudentId to use elsewhere outside of the scope of the
I want to return all application dates for the current month and for the
Using DQL I want to return all the documents under the Cabinet test .
Let's say I have the following class X where I want to return access
I'm writing a web service, and I want to return the data as XHTML.
I have a nullable property, and I want to return a null value. How

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.