×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Some in_array logic help please?

Some in_array logic help please?

Some in_array logic help please?

(OP)
I've been playing with this for way too long. So I thought I would ask here.

I'm trying to check if a array element value can be found as a data element in a reference array. I'm using this:
if (!in_array($arg, $arrayname, true)) {
this would occur if the $arg value is NOT found in the array
}

What I'm experiencing is even if the searched arrayname contains a substring of the $argument is returning true.
Example:

If I search for abc and the array element contains abcdef it would return found.

What do I need to do to assure the element I'm testing for is the exact same match as the argument value?
example:

If the argument was abc then the array element value must be exactly abc


Any hint, suggestions greatly appreciated.

Thanks

RE: Some in_array logic help please?

Hi

Are you sure ? in_array() works out of the box exactly as you described :

CODE --> -a

Interactive mode enabled

php > var_dump(in_array('abc', ['abcdef']));
bool(false)

php > var_dump(in_array('abcdefghi', ['abcdef']));
bool(false)

php > var_dump(in_array('abcDEF', ['abcdef']));
bool(false)

php > var_dump(in_array('abcdef', ['abcdef']));
bool(true) 

Could you post some exact input data samples for which it fails ?

Feherke.
feherke.ga

RE: Some in_array logic help please?

(OP)
Well it turns out that the test was operating properly all along. I added the "true" option and now it does not come back true with a "contained within" match. Also, I was improperly removing my argument which gave the impression of a true when it was not. This instruction was not one that I often used. Takes time to understand how it works.

Thanks for the thoughts.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close