RE: [PHP-DB] Direct Access to an Array Item?
| From: | Bastien Koert | Date: | Wed, 09 Aug 2006 15:14:06 +0000 |
| Subject: | RE: [PHP-DB] Direct Access to an Array Item? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-42278@lists.php.net to get a copy of this message | ||
use mysql_result
mysql_result ( $result, 0, 2 )
where 2 is the offset of the fields in the row
Bastien
From: Peter Beckman <beckman@purplecow.com> To: PHP-DB Mailing List <php-db@lists.php.net> Subject: [PHP-DB] Direct Access to an Array Item? Date: Tue, 8 Aug 2006 22:34:55 -0400 (EDT) I want to access a variable within a function-returned array without setting the array to a variable first. Example -- test for equal to string 'foo' on the 4th element of a returned fetch row:if (($row = mysql_fetch_row($result))[3] == 'foo') { $user = $row; }or$bar = explode('#', $str)[2];I know I can do this in perl, but can it be done in PHP? Obviously this is pseudo code, it doesn't actually work, but I wonder if there is a way that escapes me currently? I know I can assign the result to a variable and then test the element; I am addicted to trying to cut down the amount and complexity of code. Even if you disagree with my goal as good computing practices, I simply want to know if what I ask is possible, and if so, how. :-) Beckman ---------------------------------------------------------------------------Peter Beckman Internet Guy beckman@purplecow.com http://www.purplecow.com/--------------------------------------------------------------------------- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php