Reputation: 576
I work with databases in PHP and often fetch data from one. My question is: Can I write this in one line?
$res = mssql_fetch_assoc($result);
return $res['col'];
I have tried multiple approaches including
return (mssql_fetch_assoc($result))['col'];
and
return mssql_fetch_assoc($result)['col'];
but nothing seems to work.
Any ideas?
Upvotes: 2
Views: 85
Reputation: 2664
You can use:
function getvalue($array, $key)
{
return $array[$key];
}
and then return getvalue(mssql_fetch_assoc($result),'col');
Upvotes: 1
Reputation: 437574
Only if you are on PHP >= 5.4.0, where this was implemented with the name array dereferencing.
Upvotes: 3