kwandoa Posted April 19, 2013 Share Posted April 19, 2013 list ($check, $data) = check_login ($dbc, $_POST['email'], $_POST['pass']); Regarding the above. would you be able to go into a bit more detail. Another thing ... PHP.net states that it is not really a function "Like array(), this is not really a function, but a language construct. list() is used to assign a list of variables in one operation." - php.net Link to comment Share on other sites More sharing options...
margaux Posted April 19, 2013 Share Posted April 19, 2013 list() is one of those nice functions like array_map() which does a lot of work for you in one step. In the above example, the check_login() function is called and returns an array. list() then assigns the array elements to the 2 variables which list() provides as arguments. Because functions can only return 1 variable (which of course can be an array), this technique is a neat way to call your function and assign a bunch of variables in one step. The longhand version would be $login_data = check_login ($dbc, $_POST['email'], $_POST['pass']); $check = $login_data[0]; $data = $login_data[1]; Link to comment Share on other sites More sharing options...
kwandoa Posted April 22, 2013 Author Share Posted April 22, 2013 Ok, I understand, makes sense. Could I just ask, why would you also add $dbc? Why not just email and pass? Link to comment Share on other sites More sharing options...
Antonio Conte Posted April 22, 2013 Share Posted April 22, 2013 You need to pass the Database connection resource ($dbc) along for the function to be able to use it. The theory behind this is called scope, and determines where variables are available. The $dbc variable won't exists inside the function check_login unless: 1. You pass it as an argument, as done above 2. Declare it global inside the function Passing it as an argument is considered the best practice of the two, as global variables are generally bad. That's another discussion though. Here's how you do that: function check_login($username, $password) { global $dbc; // Declare variable global. You can use it below now // Other stuff here } 2 Link to comment Share on other sites More sharing options...
kwandoa Posted April 22, 2013 Author Share Posted April 22, 2013 thank you Link to comment Share on other sites More sharing options...
Recommended Posts