Jump to content

[SOLVED] Eval multi-dimensional array not working.


lws_gnam

Recommended Posts

Hello,

 

I'm working on something where i need to be able to eval a multi-dimensional array, but for some reason it's not working!  Here's my code:

 


        $test3['going']['up'] = array('hello', 'test', 'world');
if (is_array($test3['going']['up']))
	echo '<br />Direct call is an array<br />';
else 
	echo '<br />Direct call is NOT an array<br />';
echo('is_array($test3' . "['going']['up']);");
if (eval('is_array($test3' . "['going']['up']);"))
	echo '<br />Eval call is an array<br />';
else 
	echo '<br />Eval call is NOT an array<br />';

 

Which outputs:

 

Direct call is an array
is_array($test3['going']['up']);
Eval call is NOT an array

 

I initially had:

 

        $test3['going']['up'] = array('hello', 'test', 'world');
if (is_array($test3['going']['up']))
	echo '<br />Direct call is an array<br />';
else 
	echo '<br />Direct call is NOT an array<br />';
echo('is_array($test3' . "['going']['up']);");
if (is_array(eval('$test3' . "['going']['up']);")))
	echo '<br />Eval call is an array<br />';
else 
	echo '<br />Eval call is NOT an array<br />';

 

Which produced the same output as above.

 

I need to eval the multi-dimensional array because it could be as simple as $test3['going'], or as complex as $test3['going']['going']['gone'].

 

Thanks in advance!

Ryan

 

 

Link to comment
Share on other sites

try

<?php
$test3['going']['up'] = array('hello', 'test', 'world');
if (is_array($test3['going']['up']))
	echo '<br />Direct call is an array<br />';
else 
	echo '<br />Direct call is NOT an array<br />';
echo('is_array($test3' . "['going']['up']);");
eval('$x=is_array($test3' . "['going']['up']);");
if ($x)
	echo '<br />Eval call is an array<br />';
else 
	echo '<br />Eval call is NOT an array<br />';
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.