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

 

 

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 />';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.