Gewinnspiel

September 21st & 22nd 2018 in Dresden

Gutscheincode

Gutscheincode

Code-Beispiele als

PHP 7.2

Beispiel


    <?php

    $notArray = null;

    var_dump($notArray['key']);
            
null

    <?php

    class MyIterator extends FilterIterator
    {
        public function accept()
        {
            return false != $this->current();
        }
    }

    $iterator = new MyIterator(new ArrayIterator([30, null, '0', 2, 0, 8]));

    $result = '';
    foreach ($iterator as $value) {
        $result .= $value;
    }

    var_dump($result);
            
3028

    <?php

    var_dump(
        strtr(substr('Hello World', -5), ['l' => ''])
    );
            
Word

    <?php

    $array = ['13,5', '5.7', '22.8', 5.9, 6.0];

    var_dump(
        preg_grep('/\d\.\d/', $array)
    );
            
['5.7', '22.8', 5.9]

    <?php

    $array = ['k', 'a', '3', 'Ä', 'z'];

    sort($array);

    foreach ($array as $element) {
        echo $element;
    }
            
3akzÄ

    <?php

    $array = array_flip([1, 3, 4, 5, 1]);

    foreach ($array as $element) {
        echo $element;
    }
            
4123