0

I have this PHP/HTML code:

<table>                                                                                        
  <tr>
    <td>Region:</td>
    <td>
      <select style="width:200px" name="region"> 
      <?php for( $i=0;$i<sizeof($regions);$i++) { ?>
      <option value=<?php echo($regions[$i]) ;?>><?php echo( $regions[$i]) ;?></option> 
      <?php }?>
      </select>  
    </td>
</tr>

The problem is the value displayed is ( Array ). I tried to replace echo by printf and sprintf but I have the same result. But if I replaced it with print_r I now have this information (Array ([0] => Alaska[region] => Alaska).

I need to know what I'm doing wrong and how can I fix it?

0

2 Answers 2

3

If you get Array as your output, then you're actually doing something like:

$x = array();
echo $x;

e.g. you're not outputting an ELEMENT of an array, you're trying to output the entire array.

That means $regions[$i] is itself an array, and you need a sub-index, e.g. $regions[$i][1] instead.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks i replaced it by $regions[$i][0] and it is work thanks
0

try this

foreach($regions as $region)
      <option value=<?php echo($region['region']) ;?>><?php echo( $region['region']) ;?></option> 
    <?php }?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.