class user{
protected $permissions;
public function can( $permission )
{
if (!isset($this->permissions)) {
/*
fetch permissions for this user from the database, and set the
User::permissions property, to allow caching.
*/
$cnx = $this->connexion();
$stmt = $cnx->prepare('SELECT permissions.permission_name FROM permissions, users_permissions WHERE users_permissions.user_id = ? AND users_permissions.permission_id = permissions.permission_id');
$stmt->bind_param('s', $_SESSION["user_id"]);
$stmt->execute();
$result = $stmt->get_result();
$people = array("Peter", "Joe", "Glenn", "Cleveland");
var_dump($people);
$this->permissions= $result->fetch_all(MYSQLI_ASSOC);
var_dump($this->permissions);
}
return in_array($permission, $this->permissions);
}
}
(scheme 1) the result of the array looks like this :
array (size=8)
0 =>
array (size=1)
'permission_name' => string 'Peut créer une permission' (length=26)
1 =>
array (size=1)
'permission_name' => string 'Peut modifier une permission' (length=28)
2 =>
array (size=1)
'permission_name' => string 'Peut voir des comptes utilisateurs' (length=34)
i tried fetch_array
instead of fetch_all
but it returns only one row
(scheme 2) is there anyway to make that array look like this one because if it does it will work :
array (size=4)
0 => string 'Peter' (length=5)
1 => string 'Joe' (length=3)
2 => string 'Glenn' (length=5)
instantiate a user
$that_guy = new user();
if ( $that_guy->can('Peut créer une permission')) {
echo"yay";
}else {
echo"you can't";
}
is there any possible way to change the array of scheme 1 and make it look like array of scheme 2 ?