Jump to content

[SOLVED] getting individual array items from function, and traverse array


paruby

Recommended Posts

There are 2 parts to this question please...

 

1.  I have a function that creates an array.  I can call the function and return the full array.  But how do I reference a single item in the array, given the index?

 

Here is my code:

 

function createMyArray()
{
   
    $files = array();	// Create Array

    // Do some stuff to populate the array

    return($files);
}

print_r(createMyArray());

 

When I run the above code, I get the full array returned.  I want to be able to return a given index... ?

 

2.  Once I do that, I want to be able to traverse through the array and show each index value on its own page, so to speak, so page 1 displays $files[0], page 2 displays $files[1], etc., without having to run through the function again.  Can this be done for instance by setting the array as a session variable??

 

Thanx!

 

Pete

After seeing vbnullchar's response, I realized I asked the question wrong.  I want to return the full array from the function, then outside the function, reference one index or another...  This changes the answer, as vbnullchar thought I wanted to rturn 1 index from the function...  Sorry for the confusion.

 

Pete

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.