Warning: Cannot use a scalar value as an array in
There might be many situations where you need to assign values in to an array. But what if , if you didn’t declared the variable as an array, and tried assigning values to it. Some times this will create an error like ‘ Warning: Cannot use a scalar value as an array in ‘. So the solution for this is to declare the variable as array type before you trying to insert values into it.
The following example will give you a clear idea.
<?php
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
// Count table rows
$count=mysql_num_rows($result);
while($rows=mysql_fetch_array($result)){
$id[]=$rows['id'];
echo $rows['id'];
?>
In the above above code, we have assigned values $id[]=$rows['id']; This will cause the error since we have not specified that the variable is an array before that statement.
so the solution is
// Count table rows $count=mysql_num_rows($result); $id = array(); ?>
You have to declare a variable as an array before assigning values.
Happy coding
Home
See the related postsPHP Warning: Call-time pass-by-reference has been deprecated Working with Database (MySQL) Cookies in PHP Session Management Functions in php Join array elements with a string – implode |




