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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:19:44+00:00 2026-05-27T05:19:44+00:00

How can I make variable array available to whole code. For example, I need

  • 0

How can I make variable array available to whole code.

For example, I need to add integers to $ids[] inside one class or function so I can use it in regular code:

class displayClass {
    public function display($field){
        $fieldNum=0;
        $puzzle=$field;
        echo "<form action=\"index.php\" method=\"post\"><table border = \"3\" ><tr>" ;

        for($i=1;$i<=36;$i++){

            if($puzzle[$i]==0){
                echo "<td><input type=\"text\" name=\"field".$i."\" maxlength=\"1\" size=\"1\"/></td>";  
                //problem is above... need to sava ids of fields..don't know how
            }  else {

                echo "<td>".$puzzle[$i]."</td>";

            }

            if($i%6==0){
                echo "</tr><tr>";
            }
        }

        echo "</td></table></form>";
    }
}

I need to add $i to a new existing array which is outside the class.

EDIT :

how can i fix this
Strict Standards: Non-static method displayClass::display() should not be called statically in Z:\dev\organization1\project1\htdocs\web\sudoku\index.php on line 35

  • 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-27T05:19:44+00:00Added an answer on May 27, 2026 at 5:19 am

    If you’re having to do this then it’s a sign that you have design and architecture issues with the codebase you’re working with which are beyond the scope of this question.

    However to solve your immediate problem, use the global keyword:

    class displayClass {
        public function display($field){
    
            global $YOUR_VARIABLE_HERE;
    
            // for example:
            global $ids;
    
            $fieldNum=0;
            $puzzle=$field;
            echo "<form action=\"index.php\" method=\"post\"><table border = \"3\" ><tr>" ;
    
            for($i=1;$i<=36;$i++){
    
                if($puzzle[$i]==0){
                    echo "<td><input type=\"text\" name=\"field".$i."\" maxlength=\"1\" size=\"1\"/></td>";  
                    //problem is above... need to sava ids of fields..don't know how
                }  else {
    
                    echo "<td>".$puzzle[$i]."</td>";
    
                }
    
                if($i%6==0){
                    echo "</tr><tr>";
                }
            }
    
            echo "</td></table></form>";
        }
    }
    

    Assuming of course that $ids[] is truly a gobally scoped variable and not defined within an existing function or class.

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

Sidebar

Related Questions

How can I make a variable (object) available for the whole lifetime of the
Possible Duplicate: Javascript closure inside loops - simple practical example How can I make
I can make a DAO recordset in VB6/Access do anything - add data, clean
In C# you can make a block inside of a method that is not
How do you use a php variable (array) inside a mysql select statement? I
How can I make a variable into a key or a value so that
I know one can use an index into an array to specify length of
How can I make the code below into a function? # split the string
In PHP, you can make two variables point to the same data. $a =
I can make Firefox not display the ugly dotted focus outlines on links with

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.