Jump to content

[SOLVED] type checking (is_numeric vs. is_string)


nicholasstephan

Recommended Posts

I'm writing a class that implements Php's Iterator interface. Where I'm running into trouble is in the keys. I'd like to be able to respond differently to associative vs index keys, basically strings vs integers. Is there any way to check the input to the offsetGet() function.

 

Using is_string and is_numeric don't work, because any string that happens to be numeric is treated as a numbered key, rather than an associative attribute name...

 

So for example:

 

echo $arr['hello'];

 

works fine, 'hello' is a string, and the value matching that key is returned.

 

echo $arr[23];

 

does alright, 23 is a number, and the 23rd value is returned.

 

but what about:

 

echo $arr["1231231234"];

 

I have no idea why you'd make a phone number an associative key, but nevertheless, I'd like it to return the correct response... the value associated with that key, and not look for the one billion two hundred thirty million...th entry.

 

I'm a bit baffled.

 

 

Cheers

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.