In this instance, I would expect the cast to come before each variable
eg foreach ($data as ["id" => (int) $id, "name" => (string) $name])

On Thu, Feb 21, 2019, 13:28 Kalle Sommer Nielsen <ka...@php.net> wrote:

> Den tor. 21. feb. 2019 kl. 14.16 skrev Chris Riley <t.carn...@gmail.com>:
> >
> > Hi internals,
> >
> > I'd like to propose opening an rfc to make the following syntax legal:
> >
> > foreach($array as (int) $i) {}
>
> How would this interact with the foreach-list syntax?
>
> $data = [
>     ["id" => 1, "name" => 'Tom'],
>     ["id" => 2, "name" => 'Fred'],
> ];
>
> foreach ($data as ["id" => $id, "name" => $name]) {
>     echo "id: $id, name: $name\n";
> }
>
> Having something like:
> foreach ($data as (int) ["id" => $id, "name" => $name]) {
>
> Would then make both $id and $name integers?
>
> --
> regards,
>
> Kalle Sommer Nielsen
> ka...@php.net
>

Reply via email to