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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 14:01:34 2024 UTC