Okay here is the modified code - no print_r no elseif, same problem - no
return. I can't see what is wrong with the recursive function??
function page($parts, $i, $array){
foreach($parts as $part){
$page .= $part;
}
$array[$i] = $page;
$i++;
if($i < count($parts)){
array_pop($parts);
page($parts, $i, $array);
}else{
return $array;
}
}
Holografix wrote:
>
> Hi
>
> From php manual:
>
> Remember that *print_r()* will move the array pointer to the end. Use
> reset() <function.reset.html> to bring it back to beginning.
> Remove print_r($return) or add reset($return) before return $return.
>
> Regards
> holo
>
>
>
>
>
> 2007/11/12, Waigani <[EMAIL PROTECTED]>:
>>
>>
>> Can anyone tell me why the following function will not return $return and
>> yet
>> will print_r($return) as expected?
>>
>> function page($parts, $i, $array){
>>
>> foreach($parts as $part){
>> $page .= $part;
>> }
>>
>> $array[$i] = $page;
>> $i++;
>>
>> if($i < count($parts)){
>> array_pop($parts);
>> page($parts, $i, $array);
>> }
>> elseif($i = count($parts)){
>> $return = array_reverse($array);
>>
>> //this prints as expected
>> print_r($return);
>>
>> //this returns nothing
>> return $return;
>> }
>> }
>>
>> //example
>> $i = 0; $parts = array('one','two',three'); $array = array();
>>
>> //prints array
>> $array = page($parts, $i, $array);
>>
>> //returns nothing.
>> print_r($array);
>>
>> thanks,
>> Jess
>> --
>> View this message in context:
>> http://www.nabble.com/function-does-not-return-tf4790342s16154.html#a13703716
>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/function-does-not-return-tf4790342s16154.html#a13713134
Sent from the Zend Framework mailing list archive at Nabble.com.