Re: Add is_vectorlike($array) function
| From: | Eugene Leonovich | Date: | Sat, 06 May 2017 21:02:23 +0000 |
| Subject: | Re: Add is_vectorlike($array) function | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-98981@lists.php.net to get a copy of this message | ||
>
>
> >
> > I gave one use case in an earlier message: many serialisation formats
> have
> > a different form for ordered lists vs key-value pairs. As an obvious
> > example, look at JSON arrays and objects, and many other formats have
> > similar types.
> >
>
> Ah, so you would do something like
>
> private serializeArray(array $data) {
> return is_vector($data) ? $this->serializeVector($data) :
> $this->serializeAssoc($data);
> }
>
> is that right?
I do this to pack php arrays into MessagePack's arrays/maps:
https://github.com/rybakit/msgpack.php/blob/master/src/Packer.php#L112-L114
--
Thank you and best regards,
Eugene Leonovich