473,403 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Need education: Question about indirect referencing

Example:

$x=array('a'=>'ant','b'=>'boat');
$s='a';
$y='$s';
echo $x[$$y];

I want to echo the value of key 'a' by indirectly referencing it via the
variable $y. The above is NOT correct, I know.

How do I indirectly reference a variable in PHP?

TIA,

Larry Woods
Jan 15 '06 #1
3 1182
lwoods wrote:
Example:

$x=array('a'=>'ant','b'=>'boat');
$s='a';
$y='$s';
echo $x[$$y];

I want to echo the value of key 'a' by indirectly referencing it via the
variable $y. The above is NOT correct, I know.

How do I indirectly reference a variable in PHP?

TIA,

Larry Woods

$y='s';
fix your example, but I don't understand why you can't use 'echo $x[$s];' .

Darvin
Jan 15 '06 #2
lwoods wrote:
I want to echo the value of key 'a' by indirectly referencing it via
the variable $y. The above is NOT correct, I know.

How do I indirectly reference a variable in PHP?


The technique is called 'Variable variables' and looks like this:

$x=array('a'=>'ant','b'=>'boat');
$s='a';
$y='s'; // Removed the dollar sign
echo $x[$$y];
JW
Jan 15 '06 #3
That's the structure that I'm looking for.

Thanks.

Larry

"Janwillem Borleffs" <jw@jwscripts.com> wrote in message
news:43***********************@news.euronet.nl...
lwoods wrote:
I want to echo the value of key 'a' by indirectly referencing it via
the variable $y. The above is NOT correct, I know.

How do I indirectly reference a variable in PHP?


The technique is called 'Variable variables' and looks like this:

$x=array('a'=>'ant','b'=>'boat');
$s='a';
$y='s'; // Removed the dollar sign
echo $x[$$y];
JW

Jan 15 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michael | last post by:
Hi, A piece of description about multi inheritance in ISO/ANSI C++ standard is as following: A class shall not be specified as a direct base class of a derived class more than once. ...
0
by: Philip Nelson | last post by:
POSTED ON BEHALF OF DAVID OWEN (UK DB2 Users Group Chair) DB2 UK Education Conference   Westmead Hotel, Birmingham Tuesday 16th Wednesday 17th November 2004   in association with GSE  ...
13
by: ganeshb | last post by:
Hi, What C statement(s) would translate to indirect jmp in assembly? I know that function pointer invocation would translate to indirect 'call' instruction, but I am not sure what will lead to...
2
by: D H | last post by:
Hi, Hi, I was looking for your opinion on VB.NET - its long-term prospects, etc. Sorry this is vague, but it's not meant to be a troll. It's a pro-VB.NET post actually. I haven't used VB or...
3
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here...
1
by: bb nicole | last post by:
Below is my interface for resume which need to post into database... I have did it all in one page and it already can send into database which the table name resume... But my letturer now want me...
5
by: Rahul B | last post by:
Hi, I am having the following issues while trying to restrict the current user from creating any objects. Below is the privileges for the user and response when i try to create a table in that...
9
by: pereges | last post by:
Hello I need some ideas for designing a recursive function for my ray tracing program. The idea behind ray tracing is to follow the electromagnetic rays from the source, as they hit the...
15
by: ingejg | last post by:
I am starting to study internet synchronization, and my head is still spinning since internet is not my forte, however my boss is breathing down my neck at the moment. Our company has only one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.