Re: On the usage of "@" (error control operator) [message #178225 is a reply to message #178221] |
Wed, 23 May 2012 20:14 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 5/23/2012 2:45 PM, Leonardo Azpurua wrote:
> "Jerry Stuckle"<jstucklex(at)attglobal(dot)net> escribió en el mensaje
> news:jpj296$bh7$1(at)dont-email(dot)me...
>> On 5/23/2012 10:49 AM, Leonardo Azpurua wrote:
>>> So, I must search an identifier in several associative arrays. And trying
>>> to
>>> access an array element with an invalid index triggers an error.
>
> Hi,
>
> I might have a valid index or not. And if it is valid, it could be valid on
> one among several arrays.
>
> Anyway, I just learnt that isset($arr[$ndx]) does not fire an error if $ndx
> is not valid on $arr.
>
> So, instead of
>
> @$x = $arr[$ndx];
> if (isset($x)) {
> ...
> }
>
> I should have written
>
> if (isset($arr[$ndx])) {
> $x = $arr[$ndx];
> ...
> }
>
> avoiding the rather ugly original construct.
>
> Thanks!
> --
>
>
Yup, that's what isset() is for. And this way looks a lot nicer, also :)
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|