lws_gnam Posted May 23, 2008 Share Posted May 23, 2008 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 https://forums.phpfreaks.com/topic/106954-solved-eval-multi-dimensional-array-not-working/ Share on other sites More sharing options...
sasa Posted May 23, 2008 Share Posted May 23, 2008 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 https://forums.phpfreaks.com/topic/106954-solved-eval-multi-dimensional-array-not-working/#findComment-548215 Share on other sites More sharing options...
lws_gnam Posted May 23, 2008 Author Share Posted May 23, 2008 Thanks! That did the trick. I guess eval has to create a reference to the array before it works. Link to comment https://forums.phpfreaks.com/topic/106954-solved-eval-multi-dimensional-array-not-working/#findComment-548228 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.