小编Ron*_*ott的帖子

PHP匹配部分字符串的数组

如何确保字符串和数组之间不存在部分匹配?

现在我正在使用语法:

if ( !array_search( $operating_system , $exclude ) ) {
Run Code Online (Sandbox Code Playgroud)

其中$ operating_system的值具有无关的细节,永远不会只是机器人,爬行或蜘蛛.

作为一个例子,$ operating_system的值是

"Mozilla/5.0 (compatible; AhrefsBot/5.0; +http://ahrefs.com/robot/)"
Run Code Online (Sandbox Code Playgroud)

$ exclude是一组不需要的项目

$exclude = [
    'bot',
    'crawl',
    'spider'
];
Run Code Online (Sandbox Code Playgroud)

我想这个例子使IF失败,因为bot既包含在字符串中又是一个数组元素.

php arrays string if-statement

8
推荐指数
1
解决办法
156
查看次数

使用for循环表示twig中的变量

在我的服务中,我返回一个如下所示的数组:

$array = [
    'bible_anagram_word'    => $result->getBibleAnagramWord(),
    'word_1'                => $result->getWord1(),
    'word_2'                => $result->getWord2(),
    'word_3'                => $result->getWord3(),
    ...
    'word_22'               => $result->getWord22(),
    'word_23'               => $result->getWord23(),
    'word_24'               => $result->getWord24(),
    'word_25'               => $result->getWord25(),
    'Bible_verse_reference' => $result->getBibleVerseReference(),
    'Bible_verse_text'      => $result->getBibleVerseText(),
    'Bible_translation'     => $result->getBibleTranslation(),
];
Run Code Online (Sandbox Code Playgroud)

如何在for循环中表示document.word _ ##

{% for i in 1..25 %}
    {{ document.word_ ~ i|slice(0,1) }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

在PHP中,此代码为:

substr ( $this->document['word_'.$i] , 0 , 1 )
Run Code Online (Sandbox Code Playgroud)

我的失败尝试包括:

  • {{document.word_~i | slice(0,1)}}
  • {{(document.word_~i)| slice(0,1)}}
  • {{'document.word_~i'| slice(0,1)}}

symfony twig zend-framework2

3
推荐指数
1
解决办法
593
查看次数

Doctrine Where 'IN' 运算符

Doctrine 查询的这一部分仅返回“validated = 1”的结果。如何修改此查询,以便它也包含已验证 = 3 的结果?这是我的第一个“IN”。

        $query
            ->andWhere($query->expr()->in('m.validated', ':validated'))
            ->setParameter('validated', '1,3');
Run Code Online (Sandbox Code Playgroud)

doctrine

1
推荐指数
1
解决办法
1279
查看次数

具有多个 OR 条件的 ZF2 Doctrine 查询

我写了以下 Dotrine 查询:

        $query3 = $this->entityManager
            ->createQueryBuilder()
            ->select('t.textDomain , t.translationKey , t.languageIso , t.translationDate')
            ->from(
                'AMDatabase\Entity\TheVerse\TranslationsMasters',
                't'
            )
            ->groupBy('t.languageIso')
            ->orderBy(
                't.translationDate',
                'DESC'
            );

// the values of $key2 array are:
// en-US
// es-MX
// es-PR

        foreach( $translation AS $key2=>$value2 ) {               

            if ( $key2 == 'en-US' ) {

                $query3
                    ->orWhere(
                        $query3->expr()
                               ->like(
                                   't.languageIso',
                                   ':languageIso'
                               )
                    )
                    ->setParameter(
                        'languageIso',
                        $key2
                    );

            }

        }

        $result3 = $query3->getQuery()
                          ->getArrayResult();
Run Code Online (Sandbox Code Playgroud)

如何同时查询搜索所有 3 种语言的 ISO ?

  • 使用“if ($key2 == 'en-US') {”执行查询并给出预期结果。
  • 但如果我删除“if ($key2 …

doctrine mariadb symfony doctrine-orm

1
推荐指数
1
解决办法
1295
查看次数