For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > August 2006 > Direct Access to an Array Item?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Direct Access to an Array Item?
Peter Beckman

2006-08-08, 9:56 pm

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/
---------------------------------------------------------------------------
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com