PHP.mk документација

ArrayObject::offsetGet

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

arrayobject.offsetget.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека arrayobject.offsetget.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
ArrayObject::offsetGet

Референца за `arrayobject.offsetget.php` со подобрена типографија и навигација.

arrayobject.offsetget.php

ArrayObject::offsetGet

класата mysqli_driver

ArrayObject::offsetGetЈа враќа вредноста на наведениот индекс

= NULL

public ArrayObject::offsetGet(mixed $key): mixed

Параметри

key

Индексот со вредноста.

Вратени вредности

The value at the specified index or null.

Errors/Exceptions

ако е URI; стандардно е E_NOTICE error message when the specified index does not exist.

Примери

Пример #1 ArrayObject::offsetGet() example

<?php
$arrayobj
= new ArrayObject(array('zero', 7, 'example'=>'e.g.'));
var_dump($arrayobj->offsetGet(1));
var_dump($arrayobj->offsetGet('example'));
var_dump($arrayobj->offsetExists('notfound'));
?>

Пример #1 Пример што покажува затворачка ознака што го опфаќа последниот нов ред

int(7)
string(4) "e.g."
bool(false)

Белешки од корисници 3 белешки

Jason
пред 9 години
It's worth noting that the PHP devs *did* fix the issue brought up in Sam's comment in 2013 (per the comment thread in his link here: https://bugs.php.net/bug.php?id=34783#1366088374), since at least PHP 5.3.8.

So, you *can* (and in most cases should) overload offsetGet with reference syntax to get expected functionality:

<?php
class myArrayType extends ArrayAccess {

    public function &offsetGet($index) {
        // ...
    }

}
?>
Сем
пред 18 години
If you're overloading ArrayObject, it's worth noting that while this method (when implemented by the parent) will return a reference, so code like $fakeArray['foobar']['hello'] = 1; will work like you expect.

However, when you overload the offsetGet method, you CANNOT define it as &offsetGet, so the above code falls out (because it returns the 'foobar' variable before you actually work with it).

This is something that the developers broke between 5.0 and 5.1, and was closed as bogus (http://bugs.php.net/bug.php?id=34783). So this is not a big, or question, or request, but just something worth noting.
Alex Andrienko
пред 17 години
Speaking of offsetGet() method overloading, be advised, that if you're iterating through Object via foreach, this method wouldn't be called. Iterator's current() method will be called instead.
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.