Wildcards - Looking Up a Range of Similar Fields?

5 posts by 3 authors in: Forums > CMS Builder
Last Post: August 23, 2011   (RSS)

Hello, All

I'm trying to build an array from a selection of similarly entitled CMSB fields. It looks something like this...

$myArray = array($record[0]['field1'], $record[0]['field2'], $record[0]['field3'], $record[0]['field4'], $record[0]['field5'], $record[0]['field6']);

As you can see, each field name is almost identical. Only the number on the end is different.

I wondered if, instead of having to identify each field in the array individually, I could use some kind of wildcard to lookup a spread of fields with similar names.

A sort of...

$record[0]['field*']

...approach?!

Any help would be most welcome.

:0)

Perchpole

Re: [Perchpole] Wildcards - Looking Up a Range of Similar Fields?

By Jason - August 22, 2011

Hi,

Could you give an example of how you would use this wildcard/array? Let us know and we'll see if we can make any suggestions.

Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Perchpole] Wildcards - Looking Up a Range of Similar Fields?

By robin - August 23, 2011

Hey,

You could use a loop and an if to get all fields that start with 'field'. Something like:

foreach($record[0] as $key => $value) {
if(substr($key,0,5) == 'field') {
$myArray[] = $value
}
}


Hope that helps,
Robin
Robin
Programmer
interactivetools.com

Re: [robin] Wildcards - Looking Up a Range of Similar Fields?

Hi, Robin -

Brilliant! Just what I was hoping for.

Thanks,

:0)

Perch