Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在字符串内搜索时,数组\搜索返回false_Php_Arrays - Fatal编程技术网

Php 在字符串内搜索时,数组\搜索返回false

Php 在字符串内搜索时,数组\搜索返回false,php,arrays,Php,Arrays,这是密码 $description = explode("<li>", $rows['description']); var_dump($description); $find = 'annual'; $key = array_search($find, $description); var_dump($key); //echo $description[$key]; 变量$find正在输出中搜索“annual”,您可以看到数组键1中有annual,但返回false 所以我不知道我

这是密码

$description = explode("<li>", $rows['description']);
var_dump($description);
$find = 'annual';
$key = array_search($find, $description);
var_dump($key);
//echo $description[$key];
变量
$find
正在输出中搜索
“annual”
,您可以看到数组键1中有annual,但返回false


所以我不知道我错过了什么或做错了什么。我试着用数组1的整个值来测试它,以确保在数组中搜索时没有问题,但仍然得到false。还更改了相同的结果…False

您误解了
数组搜索()的功能。以下一行:

公平。没有年费。没有超限费用。无国外交易费。在线或在到期日通过电话支付至美国东部时间午夜,无需支付任何费用。另外,迟交不会提高你的APR*

包含字符串
annual
,但它不是整个字符串
annual
。换句话说,
array\u string()
不在字符串内搜索,而是尝试精确匹配

要找到您正在寻找的结果,我将搜索以下内容:

$matches = array_filter($description, function($el) {
    // evaluate the current element
    // return true if a string index is 
    // found for the target string
    return strpos($el, 'annual') !== false;
});

var_dump($matches);
这将迭代
$description
数组,并返回一个数组
$filtered
,其中包含字符串
的任何元素。或者,您可以使用
foreach
循环,并将每个匹配示例添加到
$matches
数组中

示例如下:

希望这有帮助


您误解了
数组搜索()的功能。
。以下一行:

公平。没有年费。没有超限费用。无国外交易费。在线或在到期日通过电话支付至美国东部时间午夜,无需支付任何费用。另外,迟交不会提高你的APR*

包含字符串
annual
,但它不是整个字符串
annual
。换句话说,
array\u string()
不在字符串内搜索,而是尝试精确匹配

要找到您正在寻找的结果,我将搜索以下内容:

$matches = array_filter($description, function($el) {
    // evaluate the current element
    // return true if a string index is 
    // found for the target string
    return strpos($el, 'annual') !== false;
});

var_dump($matches);
这将迭代
$description
数组,并返回一个数组
$filtered
,其中包含字符串
的任何元素。或者,您可以使用
foreach
循环,并将每个匹配示例添加到
$matches
数组中

示例如下:

希望这有帮助


您误解了
数组搜索()的功能。
。以下一行:

公平。没有年费。没有超限费用。无国外交易费。在线或在到期日通过电话支付至美国东部时间午夜,无需支付任何费用。另外,迟交不会提高你的APR*

包含字符串
annual
,但它不是整个字符串
annual
。换句话说,
array\u string()
不在字符串内搜索,而是尝试精确匹配

要找到您正在寻找的结果,我将搜索以下内容:

$matches = array_filter($description, function($el) {
    // evaluate the current element
    // return true if a string index is 
    // found for the target string
    return strpos($el, 'annual') !== false;
});

var_dump($matches);
这将迭代
$description
数组,并返回一个数组
$filtered
,其中包含字符串
的任何元素。或者,您可以使用
foreach
循环,并将每个匹配示例添加到
$matches
数组中

示例如下:

希望这有帮助


您误解了
数组搜索()的功能。
。以下一行:

公平。没有年费。没有超限费用。无国外交易费。在线或在到期日通过电话支付至美国东部时间午夜,无需支付任何费用。另外,迟交不会提高你的APR*

包含字符串
annual
,但它不是整个字符串
annual
。换句话说,
array\u string()
不在字符串内搜索,而是尝试精确匹配

要找到您正在寻找的结果,我将搜索以下内容:

$matches = array_filter($description, function($el) {
    // evaluate the current element
    // return true if a string index is 
    // found for the target string
    return strpos($el, 'annual') !== false;
});

var_dump($matches);
这将迭代
$description
数组,并返回一个数组
$filtered
,其中包含字符串
的任何元素。或者,您可以使用
foreach
循环,并将每个匹配示例添加到
$matches
数组中

示例如下:

希望这有帮助


array\u search
在数组中搜索严格值。其他任何东西基本上等同于全文搜索。您的
strpos
解决方案是一种很好的处理方法。Darragh,如果是这种情况,为什么返回false$find=“公平。无年费。无超限费。无外汇交易费。在到期日在线或通过电话支付至午夜。另外,延迟支付不会提高您的APR*”,因为我认为,由于搜索内部无法奏效,我会尝试全部价值,但这仍然是错误的。不管怎样,我现在正在使用您的解决方案。
array\u search
在数组中搜索严格值。其他任何东西基本上等同于全文搜索。您的
strpos
解决方案是一种很好的处理方法。Darragh,如果是这种情况,为什么返回false$find=“公平。无年费。无超限费。无外汇交易费。在到期日在线或通过电话支付至午夜。另外,延迟支付不会提高您的APR*”,因为我认为,由于搜索内部无法奏效,我会尝试全部价值,但这仍然是错误的。不管怎样,我现在正在使用您的解决方案。
array\u search
在数组中搜索严格值。其他任何东西基本上等同于全文搜索。您的
strpos
解决方案是一种很好的处理方法。Darragh,如果是这种情况,为什么返回false$find=“公平。无年费。无超限费。无外汇交易费。在到期日通过在线或电话支付至美国东部时间午夜,无需f