php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24234 a recursive function doesn't return an expected string
Submitted: 2003-06-17 21:47 UTC Modified: 2003-06-18 03:47 UTC
From: christian_m_caron at hotmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.3.2 OS: FreeBSD 4.8
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: christian_m_caron at hotmail dot com
New email:
PHP Version: OS:

 

 [2003-06-17 21:47 UTC] christian_m_caron at hotmail dot com
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!

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-18 03:47 UTC] mgf@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You don't do anything with the return value of the recursive call to search_array().

Please ask on a support forum such as php-general if you need more help with this.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 12:01:33 2025 UTC