Can someone please give me a hand with this?
$arr=array(2,4,5,6);
$test='arr';
echo (eval("$".$test."[0]"));
I'm trying to get it to echo 2
Thanks a lot,
Ciarán 7 1765
Ciaran schrieb:
Can someone please give me a hand with this?
$arr=array(2,4,5,6);
$test='arr';
echo (eval("$".$test."[0]"));
I'm trying to get it to echo 2
Thanks a lot,
Ciarán
Without trying it, this should work:
eval("echo $".$test."['0'];");
On Jun 15, 3:19 pm, Ciaran <cronok...@hotmail.comwrote:
Can someone please give me a hand with this?
$arr=array(2,4,5,6);
$test='arr';
echo (eval("$".$test."[0]"));
I'm trying to get it to echo 2
Thanks a lot,
Ciarán
Try this:
eval("echo $".$test."[0];");
Don't treat eval like a function that returns a string, make sure the
entire PHP statement is passed to it (including the ;).
An alternative, that looks like what you were trying to accomplish,
but without the eval would be:
echo ${$test}[0];
On Jun 15, 8:39 pm, Moot <use...@mootsoft.comwrote:
On Jun 15, 3:19 pm, Ciaran <cronok...@hotmail.comwrote:
Can someone please give me a hand with this?
$arr=array(2,4,5,6);
$test='arr';
echo (eval("$".$test."[0]"));
I'm trying to get it to echo 2
Thanks a lot,
Ciarán
Try this:
eval("echo $".$test."[0];");
Don't treat eval like a function that returns a string, make sure the
entire PHP statement is passed to it (including the ;).
An alternative, that looks like what you were trying to accomplish,
but without the eval would be:
echo ${$test}[0];
Oh great thanks , that works well. I'm used to the eval function in
flash actionscript and I just thought the php one would be the same.
What if I wanted to duplicate the original array?
$arr2=${$test};
??
Cheers
Ciaran schrieb:
On Jun 15, 8:39 pm, Moot <use...@mootsoft.comwrote:
>On Jun 15, 3:19 pm, Ciaran <cronok...@hotmail.comwrote:
>>Can someone please give me a hand with this? $arr=array(2,4,5,6); $test='arr'; echo (eval("$".$test."[0]")); I'm trying to get it to echo 2 Thanks a lot, Ciarán
Try this: eval("echo $".$test."[0];");
Don't treat eval like a function that returns a string, make sure the entire PHP statement is passed to it (including the ;).
An alternative, that looks like what you were trying to accomplish, but without the eval would be: echo ${$test}[0];
Oh great thanks , that works well. I'm used to the eval function in
flash actionscript and I just thought the php one would be the same.
What if I wanted to duplicate the original array?
$arr2=${$test};
??
Cheers
Works exactly the way you guessed ;)
On Fri, 15 Jun 2007 21:19:50 +0200, Ciaran <cr*******@hotmail.comwrote:
Can someone please give me a hand with this?
$arr=array(2,4,5,6);
$test='arr';
echo (eval("$".$test."[0]"));
I'm trying to get it to echo 2
Eval doesn't return anything if you don't tell it to. You could use a
return though (the same as in function/methods/included files).
So, to echo it, you could use: echo eval('return $'.$test.'[0]');
The curly braces method as described by others is preferable though.
--
Rik Wasmus
On Jun 15, 8:53 pm, Daniel Kempkens <Daniel.Kempk...@gmail.comwrote:
Ciaran schrieb:
On Jun 15, 8:39 pm, Moot <use...@mootsoft.comwrote:
On Jun 15, 3:19 pm, Ciaran <cronok...@hotmail.comwrote:
>Can someone please give me a hand with this? $arr=array(2,4,5,6); $test='arr'; echo (eval("$".$test."[0]")); I'm trying to get it to echo 2 Thanks a lot, Ciarán
Try this:
eval("echo $".$test."[0];");
Don't treat eval like a function that returns a string, make sure the
entire PHP statement is passed to it (including the ;).
An alternative, that looks like what you were trying to accomplish,
but without the eval would be:
echo ${$test}[0];
Oh great thanks , that works well. I'm used to the eval function in
flash actionscript and I just thought the php one would be the same.
What if I wanted to duplicate the original array?
$arr2=${$test};
??
Cheers
Works exactly the way you guessed ;)- Hide quoted text -
- Show quoted text -
Great! That seems to be the functionality I was looking for with eval.
Thanks for the help guys!
Ciaran wrote:
Can someone please give me a hand with this?
$arr=array(2,4,5,6);
$test='arr';
echo (eval("$".$test."[0]"));
I'm trying to get it to echo 2
Thanks a lot,
Ciarán
$arr=array(2,4,5,6);
$test='arr';
echo ${$test}[0];
no need of eval.
--
gosha bine
extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Phil Powell |
last post by:
I have this line in my code:
eval('$field->' . $val . '(' . $max . ',' . $errDisplayArray .
');');
where $field is a predefined class instance, $val is a string
containing the name of an...
|
by: lawrence |
last post by:
I have a string which I want to send to eval(). How can I test it
ahead of time to make sure it is valid code? I don't want to send it
to eval and get parse errors. I want to do something like...
|
by: amohajer |
last post by:
what does eval function do in javascript language and what are its
usages?
|
by: Sean McCourt |
last post by:
Hi I am doing a JavaScript course and learning from the recommed book
(JavaScript 3rd Edition by Don Gosslin)
Below is one of the exercises from the book. I get this error message
when I try to...
|
by: Larry |
last post by:
Hi there:
I have seen numerous postings about eval() and its evils on this forum.
However, one of our developers is using it in the following way,
which seems like a great use of it.
Page...
| |
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - When should I use eval?
-----------------------------------------------------------------------
The ` eval() `...
|
by: Adam C. |
last post by:
Mozilla.org suggests using the with statement to control bindings:
var f = 2;
with({f: 3}){
eval("f"); // evaluates to 3
}
But that doesn't work for binding "this".
|
by: Fett |
last post by:
I am creating a program that requires some data that must be kept up
to date. What I plan is to put this data up on a web-site then have
the program periodically pull the data off the web-site.
...
|
by: spamme |
last post by:
Hi,
As you can see from the following code, I am trying to manipulate a
large number of layers. I have read many times in the past how the
"Eval" function should be used very sparingly as it can...
|
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,...
|
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...
| |
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,...
|
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...
|
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,...
|
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...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |