Re: array filtering question



On 5/21/2012 12:42 PM, Jerry Stuckle wrote:
On 5/21/2012 11:18 AM, bill wrote:
On 5/21/2012 10:46 AM, Jerry Stuckle wrote:
On 5/21/2012 10:22 AM, bill wrote:
I have a POST array with about 200 elements.
There MAY be one or more key elements that start with deleteF~
(for example deleteF~EAP, deleteF~Lowfee)

What I want to know is if any array element begins with deleteF~

I looked at array_keys, array_filter and others, but they seem
to all
match the whole key string.

I can process the whole array myself, but I am hoping that with
all the
array functions there might be one.

It would be nice if I could apply an array function and get
back an
array with just those keys. (they are checkboxes so the value
is always
"on", just their presence is enough information.)

bill

There isn't a real easy way to do this other than going through
the whole array.

However, I think your design could be improved. Why have multiple
checkboxes with different names and the same value? Why not have
all the checkboxes with the same name and different values?

It would make processing much easier.


Thanks Jerry,

There are major deletes (the ones I mentioned) and minor
deletes AND
about another 200 fields with values. This is how it appeared
in the
feeble thing I use for a brain.

It only took me 4 lines to create the array with the keys I
need in it.
The key encodes the item to delete: apply substr to it and I
have the
items to delete and the class of item they represent (which
leads to the
file name...)

I suppose I could do it the way you suggested, but then I'd
need to get
my mind wrapped around that design and this part of the project
is 90%
complete (which of course means it is 90% incomplete).

Thanks for the reasurance.

bill


Actually, it shouldn't take any more to create the items with one
key and different ids. For instance, instead of creating
something like:

<input type="checkbox" name="deleteField1" value="on">

You create

<input type="checkbox" name="delete[]" value="Field1">

You can call your major and minor delete checkboxes different names.

In this case, all the checkboxes with the name "delete[]" will be
in $_POST['delete'] array, i.e.

$_POST['delete'][0] might equal 'Field1',
$_POST['delete'][1] might equal 'Field3' (Field 2 NOT being checked)
and so on.

I find related checkboxes (i.e. similar processing for all) to be
much easier to handle this way.


Yes, that would have been. I didn't think about an array of checkboxes. If it doesn't fall out of my brain I will do it that way next time. Many thanks.

bill
.



Relevant Pages

  • Re: Managing 70 checkboxes in financial graphing application
    ... to manage how the checkboxes interact with the data and the graph. ... I have a tab with the data series called "Data". ... This allows the graph to show blanks where data is missing as some series ... My idea is to read the status of all checkboxes into an array. ...
    (microsoft.public.excel.programming)
  • Re: array filtering question
    ... On 5/21/2012 11:18 AM, bill wrote: ... What I want to know is if any array element begins with deleteF~ ... checkboxes with different names and the same value? ...
    (comp.lang.php)
  • Re: Updating Multiple Rolls Using PHP
    ... I am retrieving records from a table and I ... checkboxes, but my update loop is not working. ... array $_POST. ... Warning: Invalid argument supplied for foreach() in X: ...
    (comp.lang.php)
  • RE: Excel 2003 VBA question
    ... the state of checkboxes until the user clicks "Ok". ... Make a temp array of 6 ... addresses as needed and increment the recipientCount ... If the sendMail function will work with a recipient string like ...
    (microsoft.public.excel.programming)
  • Re: even rows for checkbox forms with no splitting of boxes from values
    ... So I usually roll my own checkboxes. ... In the solution below I wanted to randomize the test script a little ... #this is to create an array with 25-50 strings 2-10 in length ...
    (comp.infosystems.www.authoring.cgi)