English 中文(简体)
php - 阵列要素
原标题:php - count elements of array
  • 时间:2010-11-10 16:13:56
  •  标签:
  • php
  • phpunit

最后,我要知道,我取得了多大的成功和失败。 我想利用阵列功能,但我不知道如何继续这样做:

public function array_internal($the_string)
$pass=  Array();
$failed = Array();
  if(strstr($the_string,"Success"))
    {
        $pass[] = +1;
    }
  else
    {
        $failed[] = +1;
    }

count($pass);

这一步骤是发挥所有诸如以下职能:

 try {
      $this->assertEquals("off", $this->getValue("page"));
      throw new PHPUnit_Framework_AssertionFailedError("Success");
    } catch (PHPUnit_Framework_AssertionFailedError $e) {
      $this->array_internal($e->toString());
    }

这一职能本身是ok的。 我的问题只是反之。

谢谢!

Edit I tried to do something like this:

$pass= 0;
$failed = 0;
public function array_internal($the_string)

  if(strstr($the_string,"Success"))
    {
        $pass += 1;
    }
  else
    {
        $failed += 1;
    }

$pass;
最佳回答

除计票外,你不与阵列做任何事,因此,不只使用愤怒?

$pass= 0;
$failed = 0;


public function array_internal($the_string)

  global $pass, $failed;

  if(strstr($the_string,"Success"))
    {
        $pass += 1;
    }
  else
    {
        $failed += 1;
    }

}
问题回答

为什么不把全球变量作为<条码>、和<条码>,你可以通过<条码>予以增减。 通过++和$fail++?

public function array_internal($the_string)
$pass=0;
$failed=0;
if (strstr($the_string,"Success"))
{
    $pass += 1;
}
else
{
    $failed += 1;
}

<代码>$ pass[] = +1在$pass阵列中形成新的关键数值,并将1添入新的数值。 这很可能不是你想要做的事。 关于你想要做的事情,见其他答案。

$pass=  Array();
$failed = Array();

创建新的阵列。 页: 1 您也从未使用<代码>$failed。

更简单的职能是:

public function array_internal( $the_string )
  $pass = 0; 
  if( strstr( $the_string, "Success" ) )
  {            
      $pass = 1;
  }
  return $pass;
}

和哈门人一样,你需要使用外部反射。 与Harmen不同的是,如果可能,我将不使用全球变量,而是使用一个类别变量来限制其范围。

可能属于一个类别的一个静态变量, 试验目录,称为$passes 如:

TestClass::$passes += $this->array_internal($e->toString());




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签