Welcome! Log In Create A New Profile

Advanced

Check if value is NOT in array

Posted by 77471466_Alwyn 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Check if value is NOT in array
April 24, 2012 11:28AM
I'm trying to check if a certain value is NOT in an array.
Now I know I can check if a value is in an array with in_array...

but would something like this:

Language: PHP
if (!in_array(value, array)) { ... }

work to check if the value is not in the array?

or could I do something like this:

Language: PHP
if (in_array(value, array) === false) { ... }
avatar
Mac
Re: Check if value is NOT in array
April 25, 2012 06:57AM
What do you get when you try these approaches?

There is a function for this: in_array()
Re: Check if value is NOT in array
April 25, 2012 07:02AM
mac Wrote:
-------------------------------------------------------
> What do you get when you try these approaches?
>
> There is a function for this: in_array()

I'm not getting the results I want with my approach tongue sticking out smiley

I know the in_array function...but I want to call a function when the value is not found in the array.

I'm sure I can go this route (though not good practice I assume)
Or what would you guys suggest

Language: PHP
if (in_array(value, array) { do nothing }   else { call function }
avatar
Mac
Re: Check if value is NOT in array
April 25, 2012 12:50PM
Well, it is difficult to perceive what exactly you want to do so I suggest you play around until you find a solution! Good practice smiling smiley
Re: Check if value is NOT in array
May 02, 2012 09:11AM
In the end what I did was:

Language: PHP
$result = in_array(value, array);   if (result == 0) { function }
Re: Check if value is NOT in array
May 02, 2012 03:49PM
even better, this works as well:

Language: PHP
if (!(in_array($cid, $oldCourse))) { email($courseID); }
Sorry, you do not have permission to post/reply in this forum.