php: how to control checkbox?

  • Thread starter Thread starter cutegirl666888222
  • Start date Start date
C

cutegirl666888222

Guest
I have a checkbox array that I want to make it checked or unchecked based on a string of 0&1s once I open the page; mean, if for example the string value is 011 I want the first checkbox unchecked, the second checked, and the third checked...

note: the value of string is not static

if anyone have an idea how to accomplish that please do tell...
 
http://www.tizag.com/phpT/examples/formex.php

http://www.homeandlearn.co.uk/php/php4p11.html

http://www.plus2net.com/php_tutorial/array_checkbox.php
 
<?php
$string = $_REQUEST[ 'string' ];

for( $i=0; $i< strlen($string); $i++ )
{
if( $string{$i} )
{
echo "<input type='checkbox' checked='yes'>";
}
else
{
echo "<input type='checkbox'>";
}
}

?>

The key part of this is the $string{$i} syntax. That returns the character at the $i position in the string.

Hope this helps.
 
Back
Top