Okay, I'm trying to format numbers entered in this field with a small php snippit.

$num = array( 43 ); //this is to be expanded in the future for possible numbers to store in the database

foreach($num as $key=>$value) {
   $key = $value;
   $value = "Test value $key";
}

return $num;

This is in a select list of type Integer. I'm expecting this to output "Test value 43" in the select list, and store 43 in the database for it.

I will be making this more complex, and thus the reason for using the php field here, but have simplified it to try and determine what the problem is.

Comments

tnanek’s picture

I'm using the latest CCK and Drupal versions by the way (just checked the update status page).
Edit:
And the above code only outputs 43 n the select list by the way.

Dewi Morgan’s picture

The output of your function is an array with the following structure:

array(1) {
  [0]=>
  int(43)
}

(I got this by making that code into a PHP file on its own, replacing the return with var_dump($num), and seeing what the output was).

That is, your foreach isn't modifying the array. Foreach doesn't work that way.

Try this instead:

<?php
$num = array( 43, 42, 64 );
$output = array();

foreach($num as $value) {
   $output[$value] = "Test value $value";
}

return $output;
?>

This correctly returns something of the form:

array(3) {
  [43]=>
  string(13) "Test value 43"
  [42]=>
  string(13) "Test value 42"
  [64]=>
  string(13) "Test value 64"
}