Jump to content

[SOLVED] Exact match


redfox180

Recommended Posts

let's say:

given

x=abcdef

y=cd

 

x=y false

x!=y true

The built in operators work fine for what you're describing thus far.

$x = 'abcdef';
$y = 'cd';
if($x === $y){
  echo 'true';
}else{
  echo 'false';
}

 

 

What i want is an absolute x and/or y, all in one statement. Any chance?

Say what?

Link to comment
Share on other sites

say:

 

$fpym_res= 'CARL PAID BY CASH'

$fop_cash=strpos($fpym_res, "CASH");
    if ($fop_cash===FALSE)
        $pay_cash="";
    else
        $pay_cash="CASH";

$fop_ca=strpos($fpym_res, CA);
    if ($fop_ca===FALSE)
        $pay_ca="";
    else
        $pay_ca="CA";
$pay="$pay_cash$pay_ca;

The result will be CACASH and not CASH. That's why I said if you know how to 'limit' the request to an exact match when searching for a word...

 

Link to comment
Share on other sites

In this case, you're better off explod()'ing the string into an array, trim()'ing each element, and then checking if the values you want to find exist. 

 

<?php
$fpym_res= 'CARL PAID BY CASH';
$arr = explode(' ', $fpym_res);
$arr = array_map('trim', $arr);
if(in_array('CASH', $arr)){
  echo 'cash';
}else if(in_array('CA', $arr)){
  echo 'ca';
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.