Re: [RFC] Cast in foreach

From: Date: Thu, 21 Feb 2019 13:28:01 +0000
Subject: Re: [RFC] Cast in foreach
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-104487@lists.php.net to get a copy of this message
Den tor. 21. feb. 2019 kl. 14.16 skrev Chris Riley <t.carnage@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 kalle@php.net

« previous php.internals (#104487) next »