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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:47:59+00:00 2026-06-09T01:47:59+00:00

I store the field names within an array, in hopes to dynamically create the

  • 0

I store the field names within an array, in hopes to dynamically create the variables.

I receive a illegal offset type error for the if and else, these two lines:

$data[$tmp_field] = $tmp_field[$id];

$data[$tmp_field] = 0;

I checked the post data and it is posting with the appropriate data, but I am not sure what the problem is.

$student_id stores all the students ids., for example: $student_id = array(8,9,11,23,30,42,55);

function updateStudentInfo() {
  $student_id = $this->input->post('student_id');
  $internet_student = $this->input->post('internet_student');
  $dismissed = $this->input->post('dismissed');
  $non_matriculated_student = $this->input->post('non_matriculated_student');
  $felony = $this->input->post('felony');
  $probation = $this->input->post('probation');
  $h_number = $this->input->post('h_number');
  $office_direct_to = $this->input->post('office_direct_to');
  $holds = $this->input->post('holds');

  $fields = array('internet_student', 'non_matriculated_student', 'h_number', 'felony', 'probation', 'dismissed');

  foreach($student_id as $id):
    $data = array();

    foreach($fields as $field_name):
      $tmp_field = ${$field_name};

      if(empty($tmp_field[$id])) {
        $data[$tmp_field] = 0;
      } else { 
        $data[$tmp_field] = $tmp_field[$id];
      }
    endforeach;

    print '<pre style="color:#fff;">';
    print_r($data);
    print '</pre>';

  endforeach;
}

This is the array format I desire:

Array
(
    [internet_student] => 1
    [non_matriculated_student] => 1
    [h_number] => 0
    [felony] => 0
    [probation] => 1
    [dismissed] => 0
)

Added screenshot to give you a visual of the form the data is being posted from

enter image description here

  • 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-09T01:48:01+00:00Added an answer on June 9, 2026 at 1:48 am
    foreach($student_id as $id):
        $data = array();
    
        foreach($fields as $field_name):
          $tmp_field = ${$field_name};
    
          if(empty($tmp_field[$id])) {
            $data[$field_name] = 0;
          } else { 
            $data[$field_name] = $tmp_field[$id];
          }
        endforeach;
    
        print '<pre style="color:#fff;">';
        print_r($data);
        print '</pre>';
    
      endforeach;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to store a json encoded array into a MySQL field. The
The stock ELMAH_Error table uses an nText field to store an Error entry. I
How can I store/access global variables within a monotouch application? I am retrieving the
I use NumericField write a Integer in lucene Index: doc.add( new NumericField(id,Integer.MAX_VALUE,Field.Store.YES,true) .setIntValue(123) );
When I manage my venues via web interface, I see a Store ID field.
I need a field for store only a year, not a complete date. Can
I need a field to store some information after one asp button click for
I have written a custom Django Model Field to store dateutil.relativedelta 's. The field
I want to store short arrays in a field. (I realize there are reasons
How would you store a PDF document in a field in MySQL? Currently I

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.