<?php
class SimDB {
private static $count = 0;
public static function mysqli_fetch_array($result) {
if (self::$count < 10) {
self::$count++;
return "Row" . self::$count;
} else {
return false;
}
}
public static function reset() {
self::$count = 0;
}
}
$result1 = ""; // This is simulated, so not an actual result set resource
while ($row1 = SimDB::mysqli_fetch_array($result1));
echo "Value of \$row1 => $row1\n\n";
echo "Actually store all the results\n";
SimDB::reset();
while ($row1[] = SimDB::mysqli_fetch_array($result1));
var_dump($row1);
echo "\n\n How you would actually use a while() loop\n\n";
SimDB::reset();
while ($row = SimDB::mysqli_fetch_array($result1)) {
echo "Row = $row\n";
}
Value of $row1 =>
Actually store all the results
Deprecated: Automatic conversion of false to array is deprecated in /in/Z3Q3i on line 29
array(11) {
[0]=>
string(4) "Row1"
[1]=>
string(4) "Row2"
[2]=>
string(4) "Row3"
[3]=>
string(4) "Row4"
[4]=>
string(4) "Row5"
[5]=>
string(4) "Row6"
[6]=>
string(4) "Row7"
[7]=>
string(4) "Row8"
[8]=>
string(4) "Row9"
[9]=>
string(5) "Row10"
[10]=>
bool(false)
}
How you would actually use a while() loop
Row = Row1
Row = Row2
Row = Row3
Row = Row4
Row = Row5
Row = Row6
Row = Row7
Row = Row8
Row = Row9
Row = Row10
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Value of $row1 =>
Actually store all the results
Deprecated: Automatic conversion of false to array is deprecated in /in/Z3Q3i on line 29
array(11) {
[0]=>
string(4) "Row1"
[1]=>
string(4) "Row2"
[2]=>
string(4) "Row3"
[3]=>
string(4) "Row4"
[4]=>
string(4) "Row5"
[5]=>
string(4) "Row6"
[6]=>
string(4) "Row7"
[7]=>
string(4) "Row8"
[8]=>
string(4) "Row9"
[9]=>
string(5) "Row10"
[10]=>
bool(false)
}
How you would actually use a while() loop
Row = Row1
Row = Row2
Row = Row3
Row = Row4
Row = Row5
Row = Row6
Row = Row7
Row = Row8
Row = Row9
Row = Row10