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 1782
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...@hotm ail.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...@mootsof t.comwrote:
On Jun 15, 3:19 pm, Ciaran <cronok...@hotm ail.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...@mootsof t.comwrote:
>On Jun 15, 3:19 pm, Ciaran <cronok...@hotm ail.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*******@hotm ail.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.comwrot e:
Ciaran schrieb:
On Jun 15, 8:39 pm, Moot <use...@mootsof t.comwrote:
On Jun 15, 3:19 pm, Ciaran <cronok...@hotm ail.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 existing method within the class, and
$errDisplayArray will be an array element containing text that
goes appropriately into the class method whose name is in $val.
|
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 this:
$valid = checkPHP($string);
if ($valid) {
eval($string);
} else {
$resultsObject->addToErrorResults("We wanted to send our
template to eval(), but the PHP it contained was invalid.");
|
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 use the calculator.
"document.Calculate.Input is null or not an object"
Can someone please tell me why this is?
|
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 makes Ajax request to ASP.Net web service. Web service does some
data lookup and builds a string representation of a Javascript array
which is then returned to the client. In the ajax callback, call to
eval on the returned string and voila, ...
| |
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - When should I use eval?
-----------------------------------------------------------------------
The ` eval() ` function should _only_ be used when it is necessary to
evaluate a string supplied or composed at run-time; the string
can be anything from a simple (but unpredictable) expression such
as 12*2.54 to a substantial piece of javascript code.
|
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.
My problem is that when I pull the data (currently stored as a
dictionary on the site) off the site, it is a string, I can use eval()
to make that string into a dictionary, and everything is great.
However, this means that I am using eval() on...
|
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 make code run
slowly. The following works fine on my PC, however I do not know what
will happen on other platforms, so is there an alternative to "Eval"
in this instance.
for(var i=1;i<505;i++){
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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,...
|
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...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |