Ivan Zugec

Drupal Consultant

PHP

The following:

$columns = array();
foreach($form as $f)
{
$columns += array($f['form_field_id'] => $f['label']);
}

Will create.

Array
(
[] =>
[J] => J
[1] => Title
[3] => Recruiter
[2] => Description
[4] => Job_Type
[5] => Segment
[6] => Owner
)

And this will create:

$columns = array();
foreach($form as $f)
{
$columns[] = array($f['form_field_id'] => $f['label']);
}

Just when you think you know php. You find these helpful array function.

in_array()
http://au2.php.net/in_array

array_key_exists()
http://au.php.net/array_key_exists

more array functions:
http://au.php.net/manual/en/ref.array.php

Examples of using if and foreach in drupal or general php templates:

<?php if($test == 1): ?>
do something
<?php endif; ?>

<?php if($test == 1): ?>
do something
<?php else: ?>
do something else
<?php endif; ?>

<?php foreach($items as $item): ?>
<?php echo $item->getTitle(); ?>
<?php endforeach; ?>

Subscribe to RSS - PHP