【问题标题】:display value information inside a function? [closed]在函数内显示值信息? [关闭]
【发布时间】:2022-11-10 18:50:45
【问题描述】:

如何输出有关 var_dump 中值 (1) 的信息, 在str_contains 中指定搜索什么?

$a = 1;
$b = str_contains($a, 1);  //value 1 for which to show information in var_dump

echo var_dump($b);        // prints bool(true) and not information about the value 1, 
                          // which is specified in the search 
                         

【问题讨论】:

  • 尝试过阅读文档,或者您更喜欢编写没有理解的随机代码并希望它会按照您的喜好工作?
  • 您想要/需要返回哪些信息? str_contains ... "如果 needle 在 haystack 中,则返回 true,否则返回 false。" 如果您需要返回不同的信息,您仍然可以编写自己的函数,使用 str_contains

标签: php


【解决方案1】:

str_contains 在字符串中搜索特定部分并返回布尔类型:

例如:

<?php
$string = 'The lazy fox jumped over the fence';

if (str_contains($string, 'lazy')) {
    echo "The string 'lazy' was found in the string
";
}

这里函数将返回true。另外,您可以查看: https://www.php.net/manual/en/function.str-contains.php

【讨论】:

    猜你喜欢
    • 2012-12-05
    • 2015-12-13
    • 1970-01-01
    • 1970-01-01
    • 2020-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    相关资源
    最近更新 更多