# [RFC] Cast in foreach

- Thread: https://externals.io/message/104489
- Original archive: https://news-web.php.net/php.internals/104489
- Started by Legale.legale on 2019-02-21T14:54:21+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #104489 — Legale.legale — 2019-02-21T14:54:21+00:00

URL: https://externals.io/message/104489#104489

what about:

foreach($array as $i=>$v) {} 

?On Feb 21, 2019 13:15, Chris Riley <t.carnage@gmail.com> wrote:
>
> Hi internals, 
>
> I'd like to propose opening an rfc to make the following syntax legal: 
>
> foreach($array as (int) $i) {} 
>
> Which would be functionally equivalent to 
>
> foreach($array as $i) { 
> $i=(int) $i; 
> } 
>
> Thoughts? Feedback? 
> ~C

---

## #104507 — Chris Riley — 2019-02-22T14:26:53+00:00

URL: https://externals.io/message/104489#104507

Cast would work for both key and value, although I think the instances
where you need to cast a key will be fewer.



> what about:
>
> foreach($array as $i=>$v) {}
>
> ?On Feb 21, 2019 13:15, Chris Riley <t.carnage@gmail.com> wrote:
> > […]
