当前位置: 首页>>代码示例>>PHP>>正文


PHP ArrayList::size方法代码示例

本文整理汇总了PHP中ArrayList::size方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayList::size方法的具体用法?PHP ArrayList::size怎么用?PHP ArrayList::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ArrayList的用法示例。


在下文中一共展示了ArrayList::size方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: notifyObservers

 public function notifyObservers()
 {
     for ($i = 0; $i < $this->observers->size(); $i++) {
         $observer = $this->observers->get($i);
         $observer->update($this->temperature, $this->humidity, $this->pressure);
     }
 }
开发者ID:srinathweb,项目名称:HeadFirstDesignPatternsInPHP,代码行数:7,代码来源:WeatherData.php

示例2: hasNext

 public function hasNext()
 {
     if ($this->position >= $this->items->size()) {
         return FALSE;
     } else {
         return TRUE;
     }
 }
开发者ID:srinathweb,项目名称:HeadFirstDesignPatternsInPHP,代码行数:8,代码来源:PancakeHouseMenuIterator.php

示例3: testAddSameElementTwice

 function testAddSameElementTwice()
 {
     $list = new ArrayList("string");
     $list->add("Hello there");
     $list->add("Hello there");
     $this->assertEqual(2, $list->size());
 }
开发者ID:aeberh,项目名称:php-movico,代码行数:7,代码来源:ListAddElementTest.php

示例4: notifyObservers

 /**
  * Se este objeto foi alterado, como indicado pelo método hasChanged, em seguida, 
  * notificar todos os seus observadores e, em seguida, chamar o método clearChanged 
  * para indicar que este objeto não mudou.
  * @param \Prime\util\Object $arg
  */
 public function notifyObservers()
 {
     for ($index = 0; $index < count($this->observers->size()); $index++) {
         $observer = $this->observers->get($index);
         /* @var $observer IObserver */
         $observer->update($this);
     }
     $this->clearChanged();
 }
开发者ID:primephp,项目名称:framework,代码行数:15,代码来源:Observable.php

示例5: generateTable

/**
 * Turns any supplied ArrayList or array into a HTML5 valid table. A few 
 * things to note on this function, first is that this function is dependant
 * on the second argument to supply the Table Matrix.
 * 
 * How does the Table Matrix work? Since the array needs some list of 
 * information to pull out of the items that are in the array.
 * 
 * So for example if your array looks like this:
 *      $arr = [
 *          {name: "My Name", date: "My Date", password: "Some Secret"},
 *          {name: "Start Name", date: "Some Date", password: "My Secret"},
 *          {name: "Some Name", date: "End Date", password: "Secret"}
 *      ];
 * 
 * Then most likely your table Matrix would be something like this:
 *      $matrix = [
 *          {name: "Name", method: "getName"},
 *          {date: "Date", method: "getDate"}
 *      ];
 * 
 * Why use this? Well two reasons, most obvious to help formatting, the 
 * other is to stop unwanted data being leaked into the table (In this case
 * the object $passsword)
 * 
 * @param ArrayList|array $table_data
 * @param ArrayList|array $table_matrix
 * @param ArrayList|array $classes
 * @param string $id
 * @param int $maxlength
 */
function generateTable($table_data, $table_matrix, $classes = null, $id = null, $maxlength = -1)
{
    //Validate
    if (!is_array($table_data) && !$table_data instanceof ArrayList) {
        throw new Exception('Table Data must be an Array/ArrayList');
    }
    if (!is_array($table_matrix) && !$table_matrix instanceof ArrayList) {
        throw new Exception('Table Matrix is invalid.');
    }
    //Translate
    if (is_array($table_data)) {
        $table_data = new ArrayList($table_data);
    }
    if (is_array($table_matrix)) {
        $table_matrix = new ArrayList($table_matrix);
    }
    //Coordinate
    $x = '<table';
    if ($classes !== null) {
        if (is_string($classes)) {
            $x .= ' class="' . $classes . '"';
        } else {
            if (is_array($classes) || $classes instanceof ArrayList) {
                if (is_array($classes)) {
                    $classes = new ArrayList($classes);
                }
                $x .= ' class="' . $classes->implode(' ') . '"';
            }
        }
    }
    if ($id !== null && is_string($id)) {
        $x .= ' id="' . $id . '"';
    }
    $x .= '>';
    //Now we can form our table header
    $x .= '<thead><tr>';
    foreach ($table_matrix as $thead) {
        if (!is_array($thead) && !$thead instanceof ArrayList) {
            throw new Exception('Malformed table matrix.');
        }
        if (is_array($thead)) {
            $thead = new ArrayList($thead);
        }
        if (!$thead->isKeySet('name')) {
            throw new Exception('Malformed table matrix. (Need col name)');
        }
        if (!$thead->isKeySet('method')) {
            throw new Exception('Malformed table matrix. (Need col method)');
        }
        $x .= '<th>' . $thead["name"] . '</th>';
    }
    $x .= '</tr></thead>';
    //Now the table data.
    $x .= '<tbody>';
    for ($i = 0; $i < $table_data->size(); $i++) {
        $obj = $table_data[$i];
        //Now iterate over the matrix
        $x .= '<tr>';
        foreach ($table_matrix as $thead) {
            $args = array();
            if (is_array($thead)) {
                $thead = new ArrayList($thead);
            }
            if ($thead->isKeySet("args")) {
                $args = $def["args"];
            }
            $method = $thead["method"];
            $result;
            //Definition
//.........这里部分代码省略.........
开发者ID:YourWishes,项目名称:ArrayList,代码行数:101,代码来源:index.php

示例6: calculate

 public function calculate($infix)
 {
     $postfix = new ArrayList();
     $stack = new ArrayList();
     $i = 0;
     $temp = "";
     $type = $this->getType($infix[0]);
     $lasttype = TType::OPERATION;
     $infix = trim($infix);
     while ($i < strlen($infix)) {
         $type = $this->getType($infix[$i]);
         $temp = "";
         //Get Token name
         while ($type == $this->getType($infix[$i])) {
             $temp .= $infix[$i];
             $i++;
             if ($i == strlen($infix) || $type == TType::OPERATION || $infix[$i - 1] == '(') {
                 break;
             }
         }
         //Negatives Vorzeichen zu -1* umgeschrieben (Bsp.: -3 => (-1)*3
         if ($lasttype == TType::OPERATION && $type == TType::OPERATION) {
             if ($temp == '-') {
                 $postfix->add(new Token("-1", TType::NUMBER));
                 $temp = "*";
             } else {
                 $postfix->add(new Token("1", TType::NUMBER));
                 $temp = "*";
             }
         }
         //Fehlender Operator vor Funktionen wird ergänzt
         if ($type == TType::NUMBER && $lasttype == TType::FUNC || $type == TType::FUNC && $lasttype == TType::NUMBER) {
             $i -= strlen($temp);
             $type = TType::OPERATION;
             $temp = "*";
         }
         //Add Token to Tokenlist
         switch ($type) {
             case TType::NUMBER:
                 $postfix->add(new Token($temp, $type));
                 break;
             case TType::OPERATION:
                 for ($j = $stack->size() - 1; $j > -1; $j--) {
                     if ($this->getValue($temp) > $this->getValue($stack->get($j))) {
                         $stack->add($temp);
                         break;
                     } else {
                         $postfix->add(new Token($stack->get($j), TType::OPERATION));
                         $stack->remove($j);
                     }
                 }
                 if ($stack->size() == 0) {
                     $stack->add($temp);
                 }
                 break;
             case TType::FUNC:
                 if (in_array($temp, $this->availableFunc)) {
                     $func = new FunctionC($temp);
                     $sub = substr($infix, $i);
                     $pos = $this->getLastBracket($sub);
                     $sub = substr($sub, 0, $pos);
                     while (strpos($sub, ',') !== false) {
                         $pos2 = strpos($sub, ',');
                         if (strlen($func->term) === false && $temp == "integral(") {
                             $func->term = substr($sub, 0, $pos2);
                         } else {
                             $func->parameters->add($this->calculate(substr($sub, 0, $pos2)));
                         }
                         $sub = substr($sub, $pos2 + 1);
                     }
                     $func->parameters->add($this->calculate($sub));
                     $i += $pos + 1;
                     $postfix->add(new Token(strval($func->calculate()), TType::NUMBER));
                     $type = TType::NUMBER;
                 }
                 if ($this->variable->size() != 0) {
                     foreach ($this->variable->arrayList as $v) {
                         if ($temp == $v->name) {
                             $postfix->add(new Token(strval($v->wert), TType::NUMBER));
                             $temp = "";
                             $type = TType::NUMBER;
                         }
                     }
                 }
                 break;
         }
         $lasttype = $type;
     }
     //Add operation stack to postfix
     for ($j = $stack->size() - 1; $j > -1; $j--) {
         $postfix->add(new Token($stack->get($j), TType::OPERATION));
         $stack->remove($j);
     }
     //Calculate postfix--> result
     /* Lese alle Tokens der postfix Liste nacheinander ein.
      * Schreibe alle Zahlen in einen Stack, wird eine Operation gelesen, so führe die Operation mit den letzten
      * beiden hinzugefügten Zahlen aus, lösche die beiden Zahlen und ersetze sie mit ihrem Ergebnis
      */
     $result = 0.0;
     for ($i = 0; $i < $postfix->size(); $i++) {
//.........这里部分代码省略.........
开发者ID:Bomberus,项目名称:MathParserPHP,代码行数:101,代码来源:math.php

示例7: testAddAndRemoveAndSize

 /**
  * This method tests the add, remove and
  * size method of the ArrayList.
  *
  * @return void
  */
 public function testAddAndRemoveAndSize()
 {
     // initialize a new ArrayList
     $list = new ArrayList();
     $this->assertEquals(0, $list->size());
     $list->add("Element 1");
     $list->add("Element 2");
     $list->add("Element 3");
     $this->assertEquals(3, $list->size());
     $list->remove(2);
     $this->assertEquals(2, $list->size());
 }
开发者ID:appserver-io,项目名称:collections,代码行数:18,代码来源:ArrayListTest.php

示例8: __construct

//Create our class
class MyClass
{
    public $name;
    public function __construct($name)
    {
        $this->name = $name;
    }
}
//Create our Objects
$object1 = new MyClass('Hello');
$object2 = new MyClass('World');
$object3 = new MyClass('How');
$object4 = new MyClass('Are');
$object5 = new MyClass('You');
//Create our ArrayList
$myList = new ArrayList();
$myList->add($object1);
$myList->add($object2);
$myList->add($object3);
$myList->add($object4);
$myList->add($object5);
//Create our loop
for ($i = 0; $i < $myList->size(); $i++) {
    echo $myList[$i]->name . " ";
}
//Will Print: "Hello World How Are You "
foreach ($myList as $obj) {
    echo $obj->name . " ";
}
//Will Print: "Hello World How Are You "
开发者ID:YourWishes,项目名称:ArrayList,代码行数:31,代码来源:index.php


注:本文中的ArrayList::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。