note 116892 added to functions.user-defined

From: Date: Mon, 16 Mar 2015 17:31:18 +0000
Subject: note 116892 added to functions.user-defined
Groups: php.notes 
Request: Send a blank email to php-notes+get-201962@lists.php.net to get a copy of this message
You can also call function from itself. For example, I want to reach the deepest value in multidimensional array and I call function from inside the very same function. In this example function behave as some meta-loop. <?php $arr1=array('a'=>array('e'=>array('f'=>array('g'=>'h', 'n' )),'b','c')); $arr2=array('a'=>array('e'=>array('f'=>array('g'=>array('l'=>array('m'=>'w','q')), 'n' )),'b','c')); function Deep($array){ foreach($array as $key){ if(is_array($key)){ return Deep($key);//calling the function inside the function }else { echo $key; } } } echo Deep($arr1); //outputs: hn echo Deep($arr2); //outputs: wq ?> ---- Server IP: 72.52.91.14 Probable Submitter: 24.135.136.22 ---- Manual Page -- http://php.net/manual/en/functions.user-defined.php Edit -- https://master.php.net/note/edit/116892 Del: integrated -- https://master.php.net/note/delete/116892/integrated Del: useless -- https://master.php.net/note/delete/116892/useless Del: bad code -- https://master.php.net/note/delete/116892/bad+code Del: spam -- https://master.php.net/note/delete/116892/spam Del: non-english -- https://master.php.net/note/delete/116892/non-english Del: in docs -- https://master.php.net/note/delete/116892/in+docs Del: other reasons-- https://master.php.net/note/delete/116892 Reject -- https://master.php.net/note/reject/116892 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#201962) next »