1. 程式人生 > >php7.2 廢棄each方法

php7.2 廢棄each方法

<?php
$b = array();
each($b);

// Deprecated:  The each() function is deprecated. This message will be suppressed on further calls

each方法替換為

function fun_adm_each(&$array){
   $res = array();
   $key = key($array);
   if($key !== null){
       next($array); 
       $res[1] = $res['value'] = $array[$key];
       $res[0] = $res['key'] = $key;
   }else{
       $res = false;
   }
   return $res;
}