How assign names for every key
i have array
$fullname = $_POST['fullname'];
$company_name = $_POST['company_name'];
$email = $_POST['email'];
$address = $_POST['address'];
$telephone = $_POST['telephone'];
$comment = $_POST['comment'];
$data = array ( "Full Name :" => $fullname,
"Company :" => $company_name,
"email :" => $email,
"address :" => $address,
"telephone :" => $telephone,
"mobile :" => $mobile,
"comment :" => $comment);
i want show resul such as (Fullname : $fullname Email: $email)
to send it as email
and add array in string 开发者_开发知识库using implode(" ",$data)
what can i do??
$fields = array('fullname' => 'Full Name', 'company_name' => 'Company', 'email'=>'Email', 'address' => 'Address', 'telephone'=>'Telephone', 'comment'=>'Comment');
$string = "(";
foreach($fields as $field_name => $field_label)
{
if(isset($_POST[$field_name]))
{
$string .= $field_label .' :' . $_POST[$field_name] . ' ';
}
}
$string .= ')';
Have a map of your $_POST keys mapping to their respective labels:
$arr = array('fullname' => 'Fullname:'); // etc
$data = array();
foreach($_POST as $k => $v) {
if(array_key_exists($k, $arr)) {
$data[$arr[$k]] = $v;
}
}
I would just use var_export()
to print it out for the email:
var_export()
gets structured information about the given variable. It is similar tovar_dump()
with one exception: the returned representation is valid PHP code.
So:
$output = var_export($data, true);
// $output goes into your email
精彩评论