Hi guys,
Still going through these tutorials, and i've run into a message, and am wondering why I am getting it...
Notice: Array to string conversion in C:\wamp\www\lr\core\functions\users.php on line 26
this is what is on line 26:
$fields = implode('', $func_get_args); // taking an array and converting it to a string
I searched the forums and found a few posts...like this
one where to talks about looping it..I don't know if I would need to do this when the guy in the tutorial didn't need to...
When the guy in the tutorial echos out the variable - he gets:
useridusernamepasswordfirst_namelast_name_email
When I echo it out, I not only get the notice message, but also get:
Array,user_id,username,password,first_name,last name,email (mine has array in front of it, not sure if this is causing the issue?)
Here is my full code:
users.php
//pass in any number of fields and return it in an array.
//check line line in init.php - begins with $user_data - we created those lines in init.php
// so we can access more data passed through the function than just $user_id
function user_data($user_id) {
$data = array();
$user_id = (int)$user_id; //create an integer from that input, so remove any other characters
$func_num_args = func_num_args(); //shows 7 - how may paremeters we have passed through to this functino
$func_get_args = func_get_args();
// print_r($func_get_args);
//this line above prints the following out on the screen:
// Array ( [0] => 1 [1] => Array ( [0] => user_id ) [2] => user_id [3] => username [4] => password [5] => first_name [6] => last name [7] => email )
//spits out the data we defined in line 20 in init.php
if ($func_num_args > 1) {
unset($func_get_args[0]); //unset first element of the array, the reason we remove it is b/c we want to create a field set from this data
//print_r($func_get_args);
// When we print the array now, we get:
// Array ( [1] => Array ( [0] => user_id ) [2] => user_id [3] => username [4] => password [5] => first_name [6] => last name [7] => email )
$fields = implode('', $func_get_args); // taking an array and converting it to a string
echo $fields;
}
}
init.php
//create a variable, equal to the user_data function, and we might pass in the session id- $_SESSION ID
//$_SESSION['user_id'] (replaced with $session_user_id) - first name, last name, email, etc...and within the user_data function
// we now have access to anything beyond this and we can access these variable and that is useful
// because we don't need to define what we pass through to this and what we return, so essentially $user_data
// is going to be returning all this data from the database.
// if the user is logged in, we know want to grab this data
if(logged_in() === true) {
$session_user_id = $_SESSION['user_id']; //we are taking this from line 64 in login.php
$user_data = user_data($session_user_id,['user_id'], 'user_id', 'username', 'password', 'first_name', 'last name', 'email');
}
Thank you kindly for all the help I have received,