I have searched and read all sorts of options on the web in answer to this question but it seem that everyone makes it much harder than I imagined it to be...

Could someone tell me if this will work or if I just have a real misconception of the returned array issue.?

This is a shorthand version of my function

function NewPos($sequence,$member,$prev_id,$prev_loc,$type,$under_mem,$trans) {
// ... many lines of code
// sample variables assigned

$new_pos_id='1001';
$follow_id='1000033';

return array($new_pos_id,$follow_id);

then the call to the function to retrieve the two values as elements in an array

     $pos_id = NewPos($mk_pos,$pos_member,$prev_num,$prev_loc,$type,$under_mem,$sent_id);

//  this should give me 2 variables
$position = $pos_id[0];
$follow_id = $pos_id[1];

What I get in return is a blank $position, but the $follow_id is correct...

Been banging my head against the wall for a couple hours with this, and just don't understand what it is that I'm doing wrong...

Any help would be greatly appreciated.

thanks
Douglas

Well... What is in those variables... They could be the issue since we can see all of the code...

Sorry, guess I didn't make it clear the first time

What I get in return is a blank $position, but the $follow_id is correct...

What I meant was the
$pos_id[0] variable return blank, although it does have a value inside the function
and the
$pos_id[1] variable returns the expected value that it is assigned within the function.

try

$these_items = NewPos($mk_pos,$pos_member,$prev_num,$prev_loc,$type,$under_mem,$sent_id);
## loop through the output
foreach($these_items as $pos_id){

$position = $pos_id[0];
$follow_id = $pos_id[1];

}

let me add something, to make it a lot easier for you to grab the array output of a function without relying so much on the integer indexer, we can do it like this also;

<?php

function some_Array($name,$last,$address){
        $arrayItem = array();
        $arrayItem['name'] = $name;
        $arrayItem['last'] = $last;
        $arrayItem['address'] = $address;

        $output_Array[] = $arrayItem;

        return $output_Array;

}

$id = some_Array('poor','boy','north pole');

    foreach($id as $pos_id){

    echo 'Name: '. $pos_id['name'] .' '. $pos_id['last'];
    echo '<br/>';
    echo 'Location: '. $pos_id['address'];

    }

OK, just so there is no confusion... The error was mine.

After spending much time trying to make the offerings of solutions work, it finally dawned on me that maybe it wasn't that process, but something else that was causing the problem.

I went back to the source of the data (the function) only to find that there was an error in it that was causing the erroneous information to be returned...

As it turns out, the original scripting for the call to the function and the return of the array work perfectly fine. And I'm sure that the suggestions in here work as well, but I'm going to stick with the original because to me it is the cleanest and easiest to understand.

Thank you to those that responded... Sorry to have wasted your efforts.

Douglas

Well... you figured it out, so it wasn't a waste of efforts :)... It's the whole idea of this site! To learn from mistakes, ideas, references, etc.!

Mark this thread solved and give points if this thread has been answered!

Here is a bunny:
(\/)
( '.')
c('')('')

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.