Let's say I have a function in php like this:
<?php function hello() {
$x = 2;
}
and I want to use that variable outside of this function without using global, since I've heard it's a bad idea because of it's security issues. (right?).
Anyway, what is the best way to get this value out? I would be able to do this in java by using "this". But not sure how that works in PHP. Thanks.
Update:
This is the code I needed help with:
<?php
require('includes/connect.php');
function connectHouseObjects() {
global $mysqli;
/* Register a prepared statement */
if ($stmt = $mysqli->prepare('SELECT x FROM house_room1 WHERE user_id = ?')) {
/* Bind parametres */
$stmt->bind_param('i', $user_id);
/* Insert the parameter values */
$user_id = 1;
/* Execute the query */
$stmt->execute();
/* Bind resultatet */
$stmt->bind_result($x);
while ($stmt->fetch()) {
//looping through the x's and y's
}
/* Close statement */
$stmt->close();
return $x;
} else {
/* Something went wrong */
echo 'Something went terrible wrong' . $mysqli->error;
}
}
?>
return $x.$xcan be an array which holds multiple values.