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
https://forums.phpfreaks.com/topic/87264-solved-exact-match/#findComment-446454
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
https://forums.phpfreaks.com/topic/87264-solved-exact-match/#findComment-446467
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
https://forums.phpfreaks.com/topic/87264-solved-exact-match/#findComment-446474
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.