chop Posted September 6, 2015 Share Posted September 6, 2015 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 More sharing options...
Necuima Posted September 7, 2015 Share Posted September 7, 2015 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 More sharing options...
Larry Posted September 7, 2015 Share Posted September 7, 2015 You're very close. You'd just use $$report_type, which gets evaluated to $overview (if $report_type == 'overview'). Link to comment Share on other sites More sharing options...
Recommended Posts