Jump to content
Larry Ullman's Book Forums

How Do I Access Array Values When The Array Name Is Stored In A Variable


Recommended Posts

I have an array $overview() which consists of a list of column header names.

I have a variable $report_type  which contains the name "overview"

 

When the form is submitted I need to access the values in $overview() when given $report_type

 

in_array ($sort, '$'.$report_type)

 

I want to find out if $sort is in the array $overview. I tried the above but get the error that a string was given in the second parameter instead of an array.

 

again: $report_type="overview" which contains a list of column names which I am checking to see if it contains the value in $sort.

 

 

thanks

Link to comment
Share on other sites

Hi,

 

Here's a simple example of using 'in_array':

 

 

// Validate the type. Must be jpg.
      $allowed = array ('image/jpeg', 'image/pjpeg');
      if (in_array($_FILES['upload']['type'], $allowed))

 

The $_FILES is just a super-global, so the test checks to see if the upload type, which is just a variable, is in the $allowed array.

 

Hope it helps.

Link to comment
Share on other sites

 Share

×
×
  • Create New...