Highlight active link

12 posts by 5 authors in: Forums > CMS Builder
Last Post: March 9, 2010   (RSS)

By Dave - March 8, 2010

Hi aev,

>Is this a shortcut for creating a foreach loop on the array

Yes, basically it is.

array_pluck() is a function we wrote that returns an array of a specific field from an array of records.

So you could say:
$recordNums = array_pluck($records, 'num'); or
$fullNames = array_pluck($accounts, 'fullname');

Then in_array() is a php function that returns true if a value if found in an array. So you can say:
if (in_array($record['num'], $recordNums)) { echo "hello"; }

Or combining them:
if (in_array($record['num'], array_pluck($records, 'num'))) { echo "hello"; }
if (in_array("John Doe", $fullNames)) { echo "Found John!"; }

Which is the same as:
foreach ($testRecords as $testRecord) {
if ($testRecord['num'] == $record['num']) {
echo "hello";
break;
}
}


Hope that helps!
Dave Edis - Senior Developer
interactivetools.com