Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with list() function in PHP

Tags:

php

I've written the code below:

$release_id = intval(filter_var($_GET["rid"],FILTER_SANITIZE_STRING));
$query = "select * from press_releases where id = {$release_id}";

$result = $db->query($query);
$row = $result->fetch_assoc();

list($id, $short_description, $description, $created_date) = $row;

$db->close();

and I am using the variables such as $description, $short_description inside of the html tags but nothing shows. If I use the code below which is same except for the list() function:

$release_id = intval(filter_var($_GET["rid"],FILTER_SANITIZE_STRING));
$query = "select * from press_releases where id = {$release_id}";

$result = $db->query($query);
$row = $result->fetch_assoc();

$id = $row["id"];
$short_description = $row["short_description"];
$description = stripslashes(html_entity_decode($row["description"]));
$created_date = $row["created_date"];

$db->close();

it works perfectly. Basically list() function cannot assign the values coming from the $row array.

I don't understand why?

like image 468
Tarik Avatar asked Jul 19 '26 09:07

Tarik


1 Answers

According to the PHP docs for list():

list() only works on numerical arrays and assumes the numerical indices start at 0.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!