Re: Determine which are user defined keys?
| From: | Zoltán Németh | Date: | Fri, 11 Jan 2008 13:25:24 +0000 |
| Subject: | Re: Determine which are user defined keys? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-267077@lists.php.net to get a copy of this message | ||
2008. 01. 11, péntek keltezéssel 08.12-kor Christoph Boget ezt írta:
> Given the following array:
>
> <?php
> $myArr = array( 'joe' => 'bob', "0" =>
> 'briggs', 'whatever', 'whereever');
> echo '<pre>' . print_r( $myArr, TRUE ) . '</pre>';
> ?>
>
> Array
> (
> [joe] => bob
> [0] => briggs
> [1] => whatever
> [2] => whereever
> )
>
> "joe" and "0" are keys that I created whereas the key "1" and
> "2" are
> keys assigned by PHP when the array was created. When iterating
> through an array, is there a way to determine which were generated by
> PHP? I can't rely on whether or not the key is an integer because
> it's quite possible that such a key was user generated. I've gone
> through the docs and based on what I've read, I don't think something
> like this is possible but I'm hoping that's not the case.
I don't think you can do that. Why not apply some modification to the
'user created' keys, like prepend them with a _ sign or something. in
that case you can know for sure if its a php generated key or not.
greets
Zoltán Németh
>
> Any pointers?
>
> thnx,
> Christoph
>