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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:45:34+00:00 2026-06-18T06:45:34+00:00

I am attempting to write to a file using PHP. I am writing data

  • 0

I am attempting to write to a file using PHP. I am writing data from arrays.

Here’s my code:

    $subject = $_SESSION['subject'];
    $section = $_SESSION['section'];
    $exam1 = $_SESSION['exam1'];
    $exam2 = $_SESSION['exam2'];
    $finalexam = $_SESSION['finalexam'];
    $average = $_SESSION['average'];

    $studentArray = $_SESSION['stringArray'];

    $file = $subject . "-" . $section . ".txt";
    $fh = fopen($file, 'a');
    $size = sizeof($studentArray);
    for($i = 0; $i<$size; $i++){
        fwrite($fh, $studentArray[$i] . " " . $exam1[$i] . " " . $exam2[$i] . " " .       $finalexam[$i] . " " . $average[$i] . " ");
}

I always get this notice when I try to access this page:

 Notice: Undefined offset: 5 in C:\xampp\htdocs\CS120\MP\Grades.php on line 26

Line 26 is the one with the fwrite in the for-loop.
There’s always a notice but the code writes to the file correctly.
Is there anything that can be done to remove/solve the notice/error?

  • 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-18T06:45:35+00:00Added an answer on June 18, 2026 at 6:45 am

    You can use

    Method 1

    array_key_exists('1',$studentArray); // check whether array position 1 exist in array $studentArray
    

    Method 2

    if (isset($studentArray1])){
      // check whether array position 1 exist in array $studentArray
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to write PHP code to interact with JSON output from Mapquest's
I am attempting to write some code to read in a *.CSPROJ file using
I'm attempting to write a large CSV file, from a core data managed object
I'm attempting to write out C# string data to a UTF-8 file without a
I'm attempting to write an ASCII null character (nul) to a file from a
I am attempting to write a file using java.io, where I am trying to
I'm attempting to write some data from an object to an XML document and
I am attempting to write out an Excel file from an ASP.NET web server
I'm attempting to write a method that will read a properties file using Class.getResource(),
I'm attempting to download a zip file using this code: o = urllib2.build_opener( urllib2.HTTPCookieProcessor()

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.