-
For your first two example cases, you could use
key()
andcurrent()
to assign the values you need.$ar = $o->me; // reset isn't necessary, since you just created the array $typ = key($ar); $val = current($ar);
-
$out = array('me' => array(), 'mytype' => 2, '_php_class' => null); $expected = [key($out), current($out)];
In those cases, you can use
next()
to advance the cursor afterward, but it may not be necessary if the rest of your code doesn’t depend on that. -
For the third case, I’d suggest just using a
foreach()
loop instead and assigning$kv
inside the loop.foreach ($broken as $k => $v) { $kv = [$k, $v]; }
-
For the fourth case, it looks like the key is disregarded in
list()
, so you can assign the current value.$this->result = current($this->cache_data);
Like the first two cases, it may be necessary to advance the cursor with
next()
depending on how the rest of your code interacts with$this->cache_data
. -
Fifth can be replaced with a
for()
loop.reset($array); for ($i = 0; $i < 30; $i++) { $id = key($array); $item = current($array); // code next($array); }