473,662 Members | 2,760 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1193
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.c om> wrote in message
news:43******** *************** @news.euronet.n l...
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
1353
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. Example:
0
1299
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   Dear DB2 user,   Mark your calendar for the UK DB2 Education Conference, supported by
13
6930
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 indirect jmp (eg. jmp <register>). Ganesh
2
1684
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 VB.NET really, but I have used Realbasic (a vb clone), Java, C#, C, and Python. I work in education, and I'd like something that is easy enough for teachers and students to use to develop real, usable applications, not just to learn programming for...
3
4396
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 really understand how this could be an issue. The assemblies that the system is complaining about are ones that we build here and we're not changing version numbers on anything. The errors come and go with no apparent rhyme or reason. We do not...
1
1782
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 to seperate it in to 4 pages( 1 page is for personnel particular, 1 page is for education, 1 page is for worl experience and so on). And it is need a next button to continue it, at last user need to click on post resume button and post to database....
5
9399
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 user. Can anybody tell what is the difference between DIRECT SYSADM and Indirect SYSADM and why is Indirect SYSADM is assigned to user by default.
9
2628
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 object.The object is triangulated. The rays can undergo multiple reflections, diffractions etc of the same object i.e. a ray hits a surface of the object, undergoes reflection resulting in a reflected ray which can again hit a surface, corner or edge...
15
2704
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 server with fixed IP address provided by our ISP, while the other sites (which I wish in the future hold the replicas databases) have only standard internet connections with Dynamic IP (which means that they change IP addresses, as given by the ISP...
0
8857
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8768
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8547
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7368
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5655
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4181
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.