开发者

How assign names for every key

开发者 https://www.devze.com 2022-12-20 01:06 出处:网络
i have array $fullname = $_POST[\'fullname\']; $company_name = $_POST[\'company_name\']; $email = $_POST[\'email\'];

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 to var_dump() with one exception: the returned representation is valid PHP code.

So:

$output = var_export($data, true);
// $output goes into your email 
0

精彩评论

暂无评论...
验证码 换一张
取 消