php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39882 no array being returned from function
Submitted: 2006-12-19 12:14 UTC Modified: 2006-12-19 12:17 UTC
From: testuser at phpizabi dot net Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.4.4 OS: CENT OS 4.4 i686
Private report: No CVE-ID: None
 [2006-12-19 12:14 UTC] testuser at phpizabi dot net
Description:
------------
It seems that I am not being able to return an array from a function. I read a serialized string, unserialize it and then call a recursive  function to get the deepest keys and values

Reproduce code:
---------------
$test_serial = <<< FO
a:5:{i:0;a:7:{s:8:"question";s:31:"What is your tv watching habits";s:5:"field";s:10:"checkboxes";s:7:"default";N;s:9:"charwidth";N;s:5:"lines";N;s:6:"maxlen";N;s:7:"options";s:54:"never watch tv |always am on the tube |i dont own a tv";}i:1;a:7:{s:8:"question";s:27:"What is your favorite genre";s:5:"field";s:12:"radiobuttons";s:7:"default";N;s:9:"charwidth";N;s:5:"lines";N;s:6:"maxlen";N;s:7:"options";s:19:"horror |sex |comedy";}i:2;a:7:{s:8:"question";s:0:"";s:5:"field";s:9:"textfield";s:7:"default";s:6:"sfasdf";s:9:"charwidth";s:8:"sadfasdf";s:5:"lines";N;s:6:"maxlen";s:7:"asdfasd";s:7:"options";N;}i:3;a:7:{s:8:"question";s:27:"what is your favorite color";s:5:"field";s:9:"textfield";s:7:"default";s:0:"";s:9:"charwidth";s:0:"";s:5:"lines";N;s:6:"maxlen";s:0:"";s:7:"options";N;}i:4;a:7:{s:8:"question";s:14:"favorte things";s:5:"field";s:9:"textfield";s:7:"default";s:0:"";s:9:"charwidth";s:0:"";s:5:"lines";N;s:6:"maxlen";s:0:"";s:7:"options";N;}}
FO;

$test = unserialize($test_serial);

$test_keys = array();

$test_val = array();

function getarr_items($array,$mode){

$newarray = array();

if(is_array($array)){

foreach($array as $key => $val){

if(is_array($val)){

getarr_items($val,$mode);

}

else {

if($mode == "k"){

$newarray[] = $key;

}

else $newarray[] = $val;

}

}

}

return $newarray;

}


$test_keys = getarr_items($test,'k');

$test_val = getarr_items($test,'v');

print_r($test_keys);

echo "<------>";

print_r($test_val);


Expected result:
----------------
should return an array with values

Actual result:
--------------
empty array

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-19 12:17 UTC] tony2001@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 07:01:32 2024 UTC