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

  • Home
  • SEARCH
  • 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 8045389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:31:54+00:00 2026-06-05T05:31:54+00:00

When dealing with this array, notices are given each time the array is referenced

  • 0

When dealing with this array, notices are given each time the array is referenced until something is added to it. All of the output works as expected regardless.

A screenshot of the notices:
https://i.stack.imgur.com/6ZBuT.jpg

function create_round(&$arrTeam)
{
    $numTeams = 4;

    $used = array();

    for ($i = 0; $i < $numTeams; $i++) {
        if (!in_array($i, $used)) { //if i isnt already scheduled to play
            for ($u = $numTeams-1; $u > $i; $u--) {
                if (!in_array($u, $used) && !in_array($u, $arrTeam[$i]["games"])) { //if u isnt already scheduled to play and u hasnt been played by i before
                    $arrTeam[$i]["games"][sizeof($arrTeam[$i]["games"])] = $u;
                    $arrTeam[$u]["games"][sizeof($arrTeam[$u]["games"])] = $i;

                    $used[sizeof($used)] = $i;
                    $used[sizeof($used)] = $u;

                    echo($arrTeam[$i]["name"] . " VS " . $arrTeam[$u]["name"] . "<br>");
                    break;
                }
            }   
        }
    }

    var_dump($arrTeam);
}

function round_robin()
{
    $numTeams = 4;

    //Create array
    $arrTeam = array(
        $team = array(
            "name" => "",
            "games" => array()
        )
    );

    //TEMP ASSIGNING NAMES
    for ($i = 1; $i < $numTeams+1; $i++)
        $arrTeam[$i-1]["name"] = "Team $i"; 

    //Echo Round numbers
    for ($i = 1; $i < $numTeams; $i++) {
        echo("<br>Round $i<br>");
        create_round($arrTeam);
    }
}

round_robin();

Should notices just be disabled or is there a better way of dealing with this?

I tried padding it but the code ended up twice as long and very messy.

  • 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-05T05:31:55+00:00Added an answer on June 5, 2026 at 5:31 am

    you’re checking this one all over the place:

    $arrTeam[$i]["games"]
    

    without testing its existence.
    Change to:

    if (isset($arrTeam[$i]["games"]) && ..more checking.. ) { ..do stuff.. }
    

    or you can disable notices:

    error_reporting(E_ALL ^ E_NOTICE);
    

    EDITED:

    do this once in round_robin() function:

    instead of:

    $numTeams = 4;
    
    //Create array
    $arrTeam = array(
        $team = array(
            "name" => "",
            "games" => array()
        )
    );
    

    do:

    $numTeams = 4;
    for($x=0;$x<$numTeams;$x++) {
       $arrTeam[$x] = array("name"=>"","games"=>array());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This was the first time I encountered this kind of error after dealing with
Hi, ive been dealing with this for some time now and need your help.
I've been dealing with this problem for quite some time. What I am trying
I'm trying to display all the objects in this array (prefixes) with the variable
I have this method dealing with a couple array that I can't seem to
Good evening. This code works. It sorts an array of cards by both Suit
Given an array with integers, with each integer being at most n positions away
I'm slowly learning C. I read this page about input and output dealing with
I've been dealing with this problem for my thesis. The goal is to develop
Hey so I've been dealing with this issue for a while. So, part of

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.