3

Possible Duplicate:
String with array structure to Array

I have a strict no eval() policy at my work and I am having a hard time writing this code with out the eval().

The solution needs to work with the $location var having any number of periods in it.

How would you do this without the eval()

<?php 

$location = 'details.name.first';
$value = 'Tyler';

$data = array();
$data['details']['name']['first'] = 'Kevin';
$data['details']['name']['last'] = 'Jensen';
$data['details']['phone'] = '(434) 453-5331';

$parts = explode('.', $location);

$command = '$data';
foreach($parts as $part) {
    $command .= '["'.$part.'"]';
}
eval($command.' = $value;');


print_r($data);
Community
  • 1
  • 1
RonSper
  • 683
  • 1
  • 7
  • 18

0 Answers0