Jump to content

Search the Community

Showing results for tags 'undefined offset'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. I'm getting an error: Undefined offset: 1 in… I'm trying to display a 2D array after filling it. It displays fine if I echo it while it's being made, but after it is not working. I'm making a pyramid solitaire game and am trying to set up the pyramid of cards. There are 7 arrays, each with a set amount of cards in them. The first array only gets one cards while the last array gets seven. This makes it like a pyramid. All the indexes that don't get a card are set to 0. So it looks like this where the 1's are cards: 1 0 0 0 0 0 0 0 ​1 1 0 0 0 0 0 0 ​1 1 1 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 The display2Darray function is what is causing the error. Specifically this line: if($array[$i][$j] == 0) Heres my main code: <?php include_once "pyramidCard.php"; include_once "pyramidDeck.php"; $theDeck = new Deck(); $pyramid = array(array(), array(), array(), array(), array(), array(), array()); $size = 7; $theDeck->shuffleCards(); makePyramid($pyramid, $size, $theDeck); display2Darray($pyramid, $size); //************************ // FRUNCTIONS * //************************ function makePyramid($array, $size, $deck) { $row = 0; for($i = 0; $i < $size; $i++) { for($j = 0; $j < $size; $j++) { if($j > $row) { $array[$i][$j] = 0; //echo ". <br>"; } else { $array[$i][$j] = $deck->dealCards(); //echo "this card is ".$array[$i][$j]->getFace()." of ".$array[$i][$j]->getSuit()."<br>"; } } $row++; } } function display2Darray($array, $size) { for($i = 0; $i < $size; $i++) { for($j = 0; $j < $size; $j++) { if($array[$i][$j] == 0) echo " "; else echo $array[$i][$j]->getFace()." of ".$array[$i][$j]->getSuit(); } echo "<br>"; } } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.