php 如果数组的大小大于 1

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6961847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:41:18  来源:igfitidea点击:

if size of array is greater than 1

phparrayssizeof

提问by livinzlife

I have an end of a link set, but I only want a portion to be used UNLESS the size of an array is greater than 1.

我有一个链接集的结尾,但我只想使用一部分,除非数组的大小大于 1。

$closeLink='</a>'.'<a target=&quot;_blank&quot; href="'.implode('" rel="lightbox['.
$post->ID.']" class="single_image" title="'.$lightHtml.'<br />&lt;a href=&quot;'.
$desclinkurl.'&quot;&gt;'.$desclink.'&lt;/a&gt;"></a><a href="',$custgalarr).'"
rel="lightbox['.$post->ID.']" class="single_image" title="'.$lightHtml.'<br />&lt;a 
target=&quot;_blank&quot; href=&quot;'.$desclinkurl.'&quot;&gt;'.$desclink.'&lt;/
a&gt;"></a>';

So everything after the part shown isolated below needs to only show if the size of the array $custgalarr is greater than 1:

因此,下面显示的隔离部分之后的所有内容只需要显示数组 $custgalarr 的大小是否大于 1:

$closeLink='</a>'

I figure I need to use something like this after the closing a tag

我想我需要在关闭标签后使用这样的东西

if (sizeof($custgalarr) > 1){

Help me out, thanks in advance!

帮帮我,先谢谢了!

回答by Alex Turpin

In PHP it's

在 PHP 中它是

if (count($custgalarr) > 1)

回答by dr. null

<?php

function wordlength($txt, $limit)
{
   $words = explode(' ', $txt);
   foreach($words as $v)
   {
       if(strlen($v) > $limit)
       {
            return true;
       }
   }
   return false;
}

$txt = "1";

if(!wordlength($txt, 1))
{
    die("String is less than or equal to one.");
}

?>