Home >Backend Development >PHP Tutorial >Why am I Getting \'Array to string conversion\' Errors in PHP?
Problem Overview
During database retrieval using PHP's SELECT query, users may encounter the following error:
Notice: Array to string conversion in (pathname) on line 36.
This error occurs when an array (such as the result returned by @mysql_fetch_assoc()) is inadvertently treated as a string.
Resolving the Issue
To resolve this issue, one must identify the specific array elements containing the desired data. For instance, in the provided code snippet, the returned $money array contains a 'money' key:
<code class="php">$money = @mysql_fetch_assoc($get); echo '<p id= "status">'.$_SESSION['username'].'<br> Money: '.$money.'. </p>';</code>
Instead of treating $money as a string, use the appropriate array syntax to access the 'money' element:
<code class="php">echo '<p id= "status">'.$_SESSION['username'].'<br> Money: '.$money['money']. </p>';</code>
The above is the detailed content of Why am I Getting 'Array to string conversion' Errors in PHP?. For more information, please follow other related articles on the PHP Chinese website!