downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ArrayObject::offsetSet> <ArrayObject::offsetExists
Last updated: Fri, 13 Nov 2009

view this page in

ArrayObject::offsetGet

(PHP 5 >= 5.1.0)

ArrayObject::offsetGet指定したインデックスの値を返す

説明

mixed ArrayObject::offsetGet ( mixed $index )

パラメータ

index

値のインデックス。

返り値

指定したインデックスの値、あるいは FALSE を返します。

例1 ArrayObject::offsetget の例

<?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'));
?>

上の例の出力は以下となります。

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



add a note add a note User Contributed Notes
ArrayObject::offsetGet
Alex Andrienko
20-Jan-2009 11:58
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.
Sam
30-Nov-2007 11:01
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.

ArrayObject::offsetSet> <ArrayObject::offsetExists
Last updated: Fri, 13 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites