Arrays become null after passing to function in PHP

Posted by William on Stack Overflow See other posts from Stack Overflow or by William
Published on 2010-04-09T18:00:42Z Indexed on 2010/04/09 18:03 UTC
Read the original article Hit count: 285

Filed under:
|
|

So when I pass my filled arrays to the function createform the form is created with $max_avatars options, but they have no name or value. Why are my arrays becoming null?

<?php
    $avatar_image_name = array('hacker','samurai','cool','happy','thatsnice','angry','tv','bang');
    $avatar_name = array('Hacker','Samurai','Cool','Happy','That\'s nice','Angry','TV','Bang');

    $max_avatars = 6;
     createform($max_avatars, $avatar_image_name, $avatar_name); 
?>

The function createform:

function createform($max_avatars, $avatar_image_name, $avatar_name)
                    {
                        $string ='<table id="formtable">
                            <tr><td class="formtext">Name:</td><td><input type="text" name=name size=25 /></td></tr>            
                            <tr><td class="formtext">Trip:</td><td><input type="text" name=trip size=25 /> (<font style="color: #ff0000">Don\'t use your password</font>)</td></tr>
                            <tr><td class="formtext">Comment</td><td><textarea name=post rows="4" cols="50"></textarea></td></tr>
                            <tr><td class="formtext">Avatar:</td>
                            <td>
                            <select name=avatar>';

                        for($i = 0; $i < $max_avatars; $i++){
                            $string = ($string . '<option value="'.$avatar_image_name[i].'">'.$avatar_name[i].'</option>');
                        }

                        $string = ($string . '</select>
                            </td>
                            <tr><td class="formtext">Extra</td><td>Fortune: <input type="radio" name="extra" value="fortune" /> Poker: <input type="radio" name="extra" value="poker" /></td></tr>
                        </table>
                        <input type=submit value="Submit" id="submitbutton">');

                        echo $string;
                    }

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays