PHP variable contains loop [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
Here's the scenario, I have a form that contains checkboxes and when submitted will be sent to a certain email. I am trying to put the checked items into one string. Like option1 option2 option 3
Here is what I have done for now:
echo $message = foreach($_POST['checkbox'] as $checkbox){ echo $checkbox . "\r\n";}
Desired output of $message:
Option1
Option2
Option3

Please make it as:
$message = '';
if (! empty($_POST['checkbox'])) {
foreach($_POST['checkbox'] as $checkbox) {
$message .= $checkbox . "\r\n";
}
}

Related

Assign empty string to php variable [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Just need help fixing this php code
if ($cmtx_set_name_value == "anonymous")
{
$cmtx_set_name_value = ""
}
thanks
Try adding ; after the assignment.
$cmtx_set_name_value = "";
your code is work fine just put ; to end of line
if ($cmtx_set_name_value == "anonymous"){
$cmtx_set_name_value = "" ; }

loop round a PHP array and display all values [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have this PHP code that displays values in an array:
$header->from[0]->mailbox . "#" . $header->from[0]->host;
whats the best way to loop round to get [1], [2], [3], etc...
You can do it through a foreach loop like this:
foreach ($header->from as $from){
echo $from->mailbox . "#" . $from->host;
}
If you want to process the first element outside the loop, then you can use array_shift:
$first_from = array_shift($header->from);
$first_from->mailbox . "#" . $first_from->host;
foreach ($header->from as $from){
echo $from->mailbox . "#" . $from->host;
}

How to customize my php echo code? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i echo some data in the Author Box of my Wordpress Theme with:
<?php echo $user_info->new_user_blond; ?> <?php echo $user_info->new_user_brown; ?> <?php echo $user_info->new_user_red; ?>
The users can check one ore more checkboxes. If a user checks all 3 Checkboxes for example the result shows up in the author box as:
blond brown red
Everthing works fine, but please help me to change my code to achive this result:
blond, brown, red
When i put a "," between the codes it shows me the desired result. BUT if a user
only checks on checkbox it shows me:
blond,,
I would be very pleased if you would support me :)
<?php
$userarr = array(
$user_info->new_user_blond,
$user_info->new_user_brown,
$user_info->new_user_red,
);
$result = implode(',',array_filter($userarr));
echo $result;
?>

i need Apostrophe in a variable result MYSQL [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I receive data in this format like:
C00001,C00302,C00303,C00287,C00286,C00285,C00017
in a variable but i need in this shape:
'C00001','C00302','C00303','C00287','C00286','C00285','C00017'
i am new in mysql kindly any help
You can explode the data, modify it, then re-implode it.
$data = 'C00001,C00302,C00303,C00287,C00286,C00285,C00017';
$arr = explode(',', $data);
$new_arr = array_map(function($a){
return "'{$a}'";
}, $arr);
$new_data = implode(',', $new_arr);

send values separated by commas and uses as variables [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a variable posting to another page and when echoed out, it looks like
Acme, Upgrade Site, Kansas
I want to separate those by the comma and assign 3 variable like
$Company = ‘Acme’;
$Action = ‘Upgrade Site’;
$Location = ‘Kansas’;”
$str= 'Acme, Upgrade Site, Kansas' ;
$arr = explode(',',$str);
$Company = $arr[0];
$Action = $arr[1];
$Location = $arr[2];
try
So the best bet here I think is probably to use explode:
// Assume $inputString is your input
$explodedInput = explode(",", $inputString);
// Now, $explodedInput[0] will be Company,
// $explodedInput[1] will be "Upgrade Site", etc...
$Company = $explodedInput[0] //...

Categories