[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

display array as checkbox list

Hi, I have a script as attached. When I run this only the last value is displayed as a checkbox but not the complete array. When I run print_r($ext) and array is displayed :Array ( [0] => 204 [1] => 205 [2] => 207 )  but the check box list only show 207. Help pls? Thank you.

A
 foreach($ext_array as $ext)
     {
                $vSelect ='<input type="checkbox" id="extsn" name="extsn[]" value="' . $ext . '" />' . $ext.'<br />' ."\n";
               
                          }
}

Open in new window

0
aej1973
Asked:
aej1973
2 Solutions
 
Robert SaylorSenior DeveloperCommented:
change

$vSelect ='<input type="checkbox" id="extsn" name="extsn[]" value="' . $ext . '" />' . $ext.'<br />' ."\n";

to

$vSelect .='<input type="checkbox" id="extsn" name="extsn[]" value="' . $ext . '" />' . $ext.'<br />' ."\n";
0
 
Ray PaseurCommented:
In PHP the single equal sign is the assignment operator.  The single dot is the concatenation operator.  When you use them together like this...

$a .= $b;

... Your telling PHP to take the string value of $b and append it to the rightmost end of the string value of $a, then replace $a with the resulting concatenation.  When you use just the equal sign like this...

$a = $b;

... you're telling PHP to take the data type and value of $b and overwrite $a with it.  It's a common mistake in PHP coding to accidentally omit some of this fiddly punctuation!
0
 
aej1973Author Commented:
Thank you very much for your quick response. It worked!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now