php - return data using variable variables -
$raw_data = array ('data' => array ('id' => 'foo')); $fields = array ('id_source' => "data['id']"); foreach ($raw_data $data) { foreach ($fields $key => $path) { var_dump ($data['id']); var_dump ($$path); } } the first var_dump gives me correct value of foo. however, second 1 gives me undefined variable: data['id']. can tell me why case, since first var_dump worked confirming variable $data['id'] set.
i realized example basic , $data[$key] , change $fields = array ('id_source' => 'id'); want able go deeper multidimensional arrays when needed. why i'm trying original approach.
Comments
Post a Comment