I find I have to do this a lot in PHP: take a value stored in a variable, and put this value in an array with a key that is the same as the variable name. This pattern comes up often with CodeIgniter, but this is not a CI specific question.
What I mean is I often have to do this:
$logs = //get logs from db
$this->load->view( 'showLogs', array('logs'=>$logs) ); //load a CI view
So my question is, is there a magic function / can we write a magic function that saves some keystrokes and improves clarity by simplifying this process?
What I want is this:
$arr = my_magic_function($logs)
// $arr = array('logs'=>$logs);
I would probably call this function "array_self", possibly shortened to "a_self" and to me, it would simply read better. What bugs me is having to type the name, in my example "logs", twice, as this can be a source of frustrating typos.