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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:37:58+00:00 2026-05-25T20:37:58+00:00

I am working on a simple game where the user will randomly be generated

  • 0

I am working on a simple game where the user will randomly be generated a bingo board. Once they initialize the game (i.e. round 1 after clicking “start” on index.php), the code starts using a new controller (bingo_play.php). This controller tracks the tiles that have been marked and the information in each tile.

Here’s the code:

$card['products'] = array(
    1 => 'hamburger',
    2 => 'fries',
    3 => 'soda',
    4 => 'taco',
    5 => 'bacon',
    6 => 'onions',
    // etc.
);

if ($card['card_number'] == 1)
{
    $card['card_entries'] = array(
        'a1' => '2', 
        'b1' => '8',
        'c1' => '11',
        'a2' => '9', 
        'b2' => '14',
        'c2' => '1',
        'a3' => '16', 
        'b3' => '15',
        'c3' => '23'
    );
}

I suppose I could assign them as session data, but didn’t think that would be the best move. Not really sure as I’m brand new to Codeigniter. In just a normal PHP project, I probably would just run an include() to the function.

My question is, what is the best way to make the tiles’ id and text available through multiple function calls without having to check and assign the array in each function?

  • 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-25T20:37:59+00:00Added an answer on May 25, 2026 at 8:37 pm

    global variables and $GLOBALS can lead to a lot of problems, and on top of that can be extremely difficult to debug. They have their use, but once you start approaching every problem this way, things can get out of hand and difficult to maintain.

    My question is, what is the best way to make the tiles’ id and text
    available through multiple function calls without having to check and
    assign the array in each function?

    While I’m not 100% clear on what you’re working with, and if the card data is static or not, or if users can have several cards or update cards, these tips might help:

    If the data never changes, use the Config class to your advantage. Store it in a config file, load it, and read the items with config_item() or $this->config->item().

    If there’s more to it than just some static data, consider creating a class/library to handle everything “bingo board” related. A very simple example:

    class Bingo_Board {
    
        private $card;
    
        function get_card($id)
        {
            // Assign the values to the $card property if not set yet,
            // getting the values from the database, a file, or wherever they are
            // Randomize them, do whatever you want
            if (empty($this->card))
            {
                $this->card = array(/* your data here*/);
            }
    
            // Return the card
            return $this->card;
        }
    }
    

    Then you can access the card like so:

    $this->bingo_board->get_card();
    

    The values will be set for the duration of the request, and you can expand on this by adding functions like reset_card(), validate_card(), update_card() and so on. If you need to store many cards, just use an array for the $card property and set/get the items by array index.

    However, if you need the data to persist accross different requests, and the data is not static (for instance, it is updated after each request), you will have to use session data or store it in the database in order to retrieve it in the next request/page. Just store as little data as possible, like the card id perhaps.

    Codeigniter (and PHP for that matter) provide several ways for you to approach a problem. In the end – use whatever method works best for you. Global variables can be a nice convenient lazy way to get/set arbitrary data, but if you can avoid using them – you should.

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

Sidebar

Related Questions

I'm working on a simple game where particles are attracted to user touches. -
I'm working on a simple board game using Appcelerator Titanium for iPhone (javascript -
I'm working on a simple multiplayer game in which 2-4 players are placed at
I'm working on a simple 2D game engine in Java, and having no trouble
I'm working on a very simple game (essentially an ice sliding puzzle), for now
i am working on a simple web app which has a user model and
I am working on a simple notification service that will be used to deliver
I'm trying to write a simple game working with two threads, one thread to
i'm working on a Client-Server Game with a tilebased map. If the user changes
I'm working on a simple game design, and I wanted to break up my

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.