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

  • From: Bob Patin <bob@xxxxxxxxx>
  • To: "FX.php Discussion List" <fx.php_list@xxxxxxxxxxxxx>
  • Date: Fri, 23 Feb 2018 15:45:39 -0600

So here’s my question:

I looped around twice w/ the same student, so I want to nuke his first 
iteration and keep the 2nd:

Array ( [0] => 2090 [1] => 684 [2] => 675 [3] => 1000 [4] => 1002 [5] => 642 
[6] => [7] => [8] => [9] => [10] => ) 
Array ( [0] => 2090 [1] => 684 [2] => 675 [3] => 660 [4] => 726 [5] => 706 [6] 
=> 1139 [7] => 1191 [8] => 1246 [9] => 810 [10] => 1046 ) 

My SESSION_VAR is called

$_SESSION[’student_array’]

How would I do a loop that says, if the 1st element = 2090 (in this case), 
delete it, but then exit the loop? Also, if it’s only there once, I of course 
won’t want to delete it at all…



On Feb 23, 2018, at 3:34 PM, Bob Patin <bob@xxxxxxxxx> wrote:

OOPS! It’s you, Richard!

I said Bev; for some strange reason that’s who I thought you were. I guess if 
I’d read the email address… :)

OK, so here’s a question I have now:

My users will be able to cycle back and generate a new set of values for a 
row (the 1st dimension of the row is a student’s RECID); I don’t want them to 
create another row, but need to either

a) edit the existing row based on the the 1st dimension in the array, or
b) delete the existing row and create a new one

I’m thinking that option B is the way to go, right? Just find the appropriate 
row and delete it, then create a row like I normally do?

Thanks,

Bob Patin
Longterm Solutions
bob@xxxxxxxxxxxxxxxxxxxxx <mailto:bob@xxxxxxxxxxxxxxxxxxxxx>
615-333-6858
FileMaker 9, 10, 11, 12 & 13 Certified Developer
http://www.longtermsolutions.com ;<http://www.longtermsolutions.com/>
-
iChat: bobpatin@xxxxxx <mailto:bobpatin@xxxxxx>
Twitter: bobpatin

FileMaker Consulting 
FileMaker Hosting for all versions of FileMaker
PHP • Full email services • Free DNS hosting • Colocation • Consulting


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: