I have code like this
$word = \'foo\';
$char_buff = str_split($word);
foreach ($char_buff as $chars){
echo var_dump($chars);
}
The out
I would just use implode, much like this:
$string = implode('', $char_buff);
Sounds like you are looking for implode() http://php.net/manual/en/function.implode.php
As for the code you posted $chars .= $char; is probably what you were trying to do
So, why do you split it just to make it a string again?
$word='foo'
$char_buff = str_split($word);
$final = array();
foreach ($char_buff as $chars){
$final[] = $chars;
}
var_dump( implode('', $final) );
str_split() converts a string to an array. There's no need to use this function if you want to keep the whole word.
<?php
$word = 'foo';
$char_buff = str_split($word);
// here is the trick
$length = count($char_buff);
$char_buff[$length] = $word;
foreach ($char_buff as $chars)
{
echo var_dump($chars);
}
?>
Maybe some of you are looking for this answer. I think var_dump() is no longer necessary for this problem.
<?php
if(isset($_POST['test'])){
$result = '';
for($x=1;$x<=4;$x++){
$ans = $_POST['ans'.$x];
$result .= $ans;
}
echo $result;
}
?>
Here is the HTML
<form role="form" method="post" action="<?php echo $url;?>">
<input type="checkbox" name="ans1" value="A">A
<input type="checkbox" name="ans2" value="B">B
<input type="checkbox" name="ans3" value="C">C
<input type="checkbox" name="ans4" value="D">D
<input type="submit" name="test" value="Submit Answer">
</form>