ninnypants
03-04-2009, 11:03 PM
So I've read that when you use var inside of a php function it confines the those variables to the function, but on a function I created it breaks when I use it.
Broken:
function get_room($room){
var $rms = array('a', 'b', 'c', 'd');
var $htm = '';
for($i=0; $i<count($rms);$i++){
$htm .= '<option value="'.$rms[$i].'"';
if($rms[$i] == $room){
$htm .= 'selected="selected"';
}
$htm .= '>'.$rms[$i].'</option>';
}
return $htm;
}
Working:
function get_room($room){
$rms = array('a', 'b', 'c', 'd');
$htm = '';
for($i=0; $i<count($rms);$i++){
$htm .= '<option value="'.$rms[$i].'"';
if($rms[$i] == $room){
$htm .= 'selected="selected"';
}
$htm .= '>'.$rms[$i].'</option>';
}
return $htm;
}
Broken:
function get_room($room){
var $rms = array('a', 'b', 'c', 'd');
var $htm = '';
for($i=0; $i<count($rms);$i++){
$htm .= '<option value="'.$rms[$i].'"';
if($rms[$i] == $room){
$htm .= 'selected="selected"';
}
$htm .= '>'.$rms[$i].'</option>';
}
return $htm;
}
Working:
function get_room($room){
$rms = array('a', 'b', 'c', 'd');
$htm = '';
for($i=0; $i<count($rms);$i++){
$htm .= '<option value="'.$rms[$i].'"';
if($rms[$i] == $room){
$htm .= 'selected="selected"';
}
$htm .= '>'.$rms[$i].'</option>';
}
return $htm;
}