beginner beginner - 4 months ago 17
PHP Question

How $row =mysqli_fetch_assoc($result) ,is possible in php

We know we can't store a function in variable

$k = echo("hello");


$k = unset($_SESSION['name']);

They all will give error. because we can't store a function in variable directly, but how we can use.

$row = mysqli_fetch_assoc($result);

I know
function output an array which is stored in variable
. but how a general rule of php is violated. and we are able to store function in a variable


echo and unset are not really functions. If you check the documentation, you'll see that it says:

Return Values
No value is returned

Since no value is returned, you can't assign them to variables.

mysqli_fetch_assoc() is an ordinary function. And like any other function, you can assign its return value to a variable, or pass it as an argument to another function, or use it in an expression.

You would have a hard time programming in PHP if you couldn't assign function values to variables. You couldn't write things like:

$max = max($var1, $var2);
$current_time = time();