Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #6112
| Date | 2012-05-21 15:19 -0400 |
|---|---|
| From | bill <nobody@spamcop.net> |
| Newsgroups | comp.lang.php |
| Subject | Re: array filtering question |
| References | <GuWdnQ9JU-sg0ifSnZ2dnUVZ_omdnZ2d@cablespeedmi.com> <jpdld1$g5p$1@dont-email.me> <1718282.RzYSdqBbuY@PointedEars.de> |
| Message-ID | <18OdnWY3FbuwCCfSnZ2dnUVZ_gudnZ2d@cablespeedmi.com> (permalink) |
On 5/21/2012 1:26 PM, Thomas 'PointedEars' Lahn wrote:
> Shake wrote:
>
>> El 21/05/2012 16:22, bill escribió:
>>> 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~
>>
>> Perhaps you can use multidimensional array here.
>>
>> If you have something like:
>>
>> <input type="checkbox" name="item_1" value="x" />
>> <input type="checkbox" name="[deleteF~][item_2]" value="x" />
>> <input type="checkbox" name="item_3" value="x" />
>> <input type="checkbox" name="[deleteF~][item_4]" value="x" />
>>
>> Perhaps if better to change to:
>>
>> Then the POST will be:
>>
>> $_POST['item_1] = 'X';
>> $_POST['item_3] = 'X';
>> $_POST['deleteF~']['item_2] = 'X';
>> $_POST['deleteF~']['item_4] = 'X';
>>
>> And you can do:
>>
>> if(isset($_POST['deleteF~'])) foreach($_POST['deleteF~'] as $Item) {
>>
>> // Do things with this item.
>> }
>
> However, if for some reason the markup cannot be changed, the solution still
> is rather simple:
>
> $matching_keys = array_filter(array_keys($_POST),
> function ($key) {
> return preg_match('/^deleteF~/', $key);
> });
>
> if ($matching_keys)
> {
> /* … */
> }
>
> <http://php.net/array_keys>
> <http://php.net/preg_match>
> <http://php.net/array_filter>
>
>
> PointedEars
Thanks for the education.
Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread
array filtering question bill <nobody@spamcop.net> - 2012-05-21 10:22 -0400
Re: array filtering question Jerry Stuckle <jstucklex@attglobal.net> - 2012-05-21 10:46 -0400
Re: array filtering question bill <nobody@spamcop.net> - 2012-05-21 11:18 -0400
Re: array filtering question Jerry Stuckle <jstucklex@attglobal.net> - 2012-05-21 12:42 -0400
Re: array filtering question bill <nobody@spamcop.net> - 2012-05-21 15:13 -0400
Re: array filtering question Shake <QUITAESTO@QUITAESTO.NOES> - 2012-05-21 17:01 +0200
Re: array filtering question bill <nobody@spamcop.net> - 2012-05-21 11:20 -0400
Re: array filtering question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-05-21 19:26 +0200
Re: array filtering question bill <nobody@spamcop.net> - 2012-05-21 15:19 -0400
csiph-web