By tnanek on
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
I'm using the latest CCK and
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.
foreach() doesn't work that way
The output of your function is an array with the following structure:
(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:
This correctly returns something of the form: