How do I generate an array from a string representation of that array?

Posted by question_about_the_problem on Stack Overflow See other posts from Stack Overflow or by question_about_the_problem
Published on 2010-03-11T18:13:49Z Indexed on 2010/03/11 19:29 UTC
Read the original article Hit count: 167

Filed under:
|
|

I want to generate the array $result_array. There is no error at the page, but not works!

that not works !

//BOF: Result Array
 $result_array = '';
 $result_array .= '"messages" => "' . $errors .'",';
 $result_array .= '"this_addr_type" => "' . (int)$_REQUEST['edit'] .'",';
if (ACCOUNT_GENDER == 'true') {
 $result_array .= '"gender_male" => "' . $male .'",';
 $result_array .= '"gender_female" => "' . $female .'",';
}
 $result_array .= '"firstname" => "' . $entry['entry_firstname'] .'",';
 $result_array .= '"lastname" => "' . $entry['entry_lastname'] .'",';
if (ACCOUNT_COMPANY == 'true') {
 $result_array .= '"company" => "' . $entry['entry_company'] .'",';
}
 $result_array .= '"street_address" => "' . $entry['entry_street_address'] .'",';
if (ACCOUNT_SUBURB == 'true') {
 $result_array .= '"suburb" => "' . $entry['entry_suburb'] .'",';
}
 $result_array .= '"postcode" => "' . $entry['entry_postcode'] .'",';
 $result_array .= '"city" => "' . $entry['entry_city'] .'",';
if (ACCOUNT_STATE == 'true') {
 $result_array .= '"state" => "' . $entry['entry_state'] .'",';
}
 $result_array .= '"country" => "' . $entry['entry_country_id'] .'"';
//EOF: Result Array

  $_RESULT = array($result_array);

that works

$_RESULT = array(
 "this_addr_type" => (int)$_REQUEST['edit'],
 "gender_male" => $male,
 "gender_female" => $female,
 "firstname" => $entry["entry_firstname"],
 "lastname" => $entry["entry_lastname"],
 "company" => $entry["entry_company"],
 "street_address" => $entry["entry_street_address"],
 "suburb" => $entry["entry_suburb"],
 "postcode" => $entry["entry_postcode"],
 "city" => $entry["entry_city"],
 "state" => $entry["entry_state"],
 "country" => $entry["entry_country_id"]
);

© Stack Overflow or respective owner

Related posts about arrays

Related posts about code-generation