note 86499 modified in function.array-walk by felipe

From: Date: Wed, 22 Oct 2008 12:45:52 +0000
Subject: note 86499 modified in function.array-walk by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-145583@lists.php.net to get a copy of this message
Although the manual warned you not to unset element, but sometimes thus is very useful and work as charm: <?php $arrChnOut=array(0=>array('ID' => '13', 'ChannelName' => 'Computers' ), 1=>array('ID' => '17', 'ChannelName' => 'Computers' ), 2=>array('ID' => '18', 'ChannelName' => 'Computers' ), ); array_walk($arrChnOut, create_function('&$v, $k, $arr_rtn', 'if ($k{0}!="_"){$arr_rtn["_".$v[\'ID\']]=$v;unset($arr_rtn[$k]);}'), &$arrChnOut); var_export($arrChnOut); ?> --was-- Although the manual warned you not to unset element, but sometimes thus is very useful and work as charm: $arrChnOut=array(0=>array('ID' => '13', 'ChannelName' => 'Computers' ), 1=>array('ID' => '17', 'ChannelName' => 'Computers' ), 2=>array('ID' => '18', 'ChannelName' => 'Computers' ), ); array_walk($arrChnOut, create_function('&$v, $k, $arr_rtn', 'if ($k{0}!="_"){$arr_rtn["_".$v[\'ID\']]=$v;unset($arr_rtn[$k]);}'), &$arrChnOut); var_export($arrChnOut); http://php.net/manual/en/function.array-walk.php

« previous php.notes (#145583) next »