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


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.


4 Years
Discussion Span
Last Post by <M/>

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.



$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];


Edited by veedeoo: info added


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;


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.



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:
( '.')

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.