|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-06-18 03:47 UTC] mgf@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 10:00:02 2025 UTC |
Description: ------------ The recursive function looks in an array for a certain text. When it finds it, it returns the text. The problem is that it never returns it (but if I put a print statement instead of a return, it will print it). Reproduce code: --------------- $arr = array('0'=>array('0'=>'zero-zero','1'=>'zero-un'), '1'=>array('0'=>'un-zero','1'=>'un-un')); print search_array('zero-un', $arr); function search_array ($page, $item) { if (is_array($item)) { foreach ($item as $k => $v) { if (is_array($v)) { search_array($page, $v); } elseif ($v == $page) { return $v; } } } else { return "Not an array!"; } } Expected result: ---------------- zero-un Actual result: -------------- Nothing!