I’m trying to populate a specific value of an array, defined by a key with, variables.
The value holds a form for a syntax, the key is the identifier for it.
I’m not sure if this is the right way to this, but it’s where I am having trouble:
function create_mess($data){
echo message_list($data);
}
function message_list($data){
$messages = array(
1000 => $data['user']." logged on!",
2000 => $data['user']." comment on ".$data['user_rep']."s comment about!".$data['title'],
2010 => "You just received a reply to".$data['title']."by ".$data['user'],
3000 => $data['user'].": ".$data['title']."!"
);
return $messages[$data['mess_id']];
}
This is a trimmed down version of what I have in order to make things more clear. I’m aware that the create_mess function isn’t a very useful one right now.
Currently it always fills in all the variables. What I want to know is:
- Is it possible to only fill in the variables for the identifier key you pass through the function?
- Is this possible with an array?
- Or only if these sentences are stored in a DB?
this will just strip down the array after having filled in all the values (inefficient). If you want to conditionally fill the array, you’ll have to build some logic around the creation of the array you want to return based on the message id. For example: treat your current messages array as a “template” to build a secondary array you will return.