[fx.php_list] Re: [OFF] Simple array question

  • From: Chris Hansen <chris@xxxxxxxxxxx>
  • To: fx.php_list@xxxxxxxxxxxxx
  • Date: Fri, 23 Feb 2018 15:41:18 -0700

Prisoner exchange? :-p


On 2/23/18 3:27 PM, Beverly Voth wrote:

And I moved here from Austin. :)

Sent from miPhone

On Feb 23, 2018, at 4:30 PM, Bob Patin <bob@xxxxxxxxx
<mailto:bob@xxxxxxxxx>> wrote:

Hi Bev, 

Hope you’re doing well over there in Kentucky! You may not know that
I moved to Austin 2-1/2 years ago, so we’re not neighbors anymore…

So, my array has 11 elements to it, and x rows; is that considered a
2-dimensional array?

B



On Feb 23, 2018, at 3:23 PM, Richard DeShong <richard@xxxxxxxxxxxxxx
<mailto:richard@xxxxxxxxxxxxxx>> wrote:

Hi Bob,

Good to see you got the handle of php arrays.

Note that what you are creating is a "two dimension" array.  A one
dimension array is a simple list, just like what FM's List()
function creates, and a basic Value List.  A two dimension array is
an array of arrays, like a spreadsheet, or an FM table.  A three
dimension array is an array of arrays with an array as at least one
of the elements.  An FM table with a repeating field could be seen
as a 3 dimension array.


On 2/23/2018 12:41 PM, Bob Patin wrote:
I had a stupid parse error… finally got it. 
:)

thanks for your help!

B



On Feb 23, 2018, at 2:40 PM, Chris Hansen <chris@xxxxxxxxxxx
<mailto:chris@xxxxxxxxxxx>> wrote:

Hey Bob,

Does anything come out of the session array at all? If not, the
session may not yet be started... Do you call session_start()
before doing anything else with the session? Also, have you
declared the 'student_array' element to be an array, like so:

$_SESSION['student_array'] = array();

Once you do that, option one in your question should work just fine...

HTH

--Chris


On 2/23/18 1:37 PM, Bob Patin wrote:
OK, absolutely last question:

I’m storing the array in a session variable; I tried this:

$_SESSION['student_array'][] = array(…

and I tried this:

$_SESSION[‘student_array[]'] = array(…

but neither of those are correct; how do I add rows to an array
stored in a session var?

B


On Feb 23, 2018, at 2:33 PM, Chris Hansen <chris@xxxxxxxxxxx
<mailto:chris@xxxxxxxxxxx>> wrote:

Yeah, you need an "as" clause in that foreach:

foreach($_SESSION['student_array'] as $student){
    print_r ($student);
}

Howzzat?


On 2/23/18 1:30 PM, Bob Patin wrote:
I figured a foreach loop would be the way, but this doesn’t run:

foreach($_SESSION['student_array']){
print_r ($_SESSION['student_array']);
}

Missing something obvious, no doubt… ?



On Feb 23, 2018, at 2:24 PM, Bob Patin <bob@xxxxxxxxx
<mailto:bob@xxxxxxxxx>> wrote:

I was thinking I was going to initialize the array when the
site loaded, but hadn’t thought about just using isset().

Sometimes the easiest stuff makes me over-complicate…

Now to figure out how to return subsequent rows… ?

B



On Feb 23, 2018, at 2:20 PM, Beverly Voth
<beverlyvoth@xxxxxxxxx <mailto:beverlyvoth@xxxxxxxxx>> wrote:

DITTO! isset() = my hero. 
Beverly

Sent from miPhone

On Feb 23, 2018, at 3:17 PM, Chris Hansen <chris@xxxxxxxxxxx
<mailto:chris@xxxxxxxxxxx>> wrote:

I like using isset($someVariable) to check whether something
exists. Avoids all sorts of mess =)

--Chris








-- 
Richard DeShong
Logic Tools
510-642-5123 office
925-285-1088 cell


Other related posts: