views:

24

answers:

1

Hi all,

I am learning cakePHP 1.26.

I got a HTML Select tag with some options like this:

<form method="post" action="/testing">  
<table border="1">  
<tr>    
<td>
<select name="data[Test][number]">  
<option name="editquote" value="[29,1]">One</option>    
<option name="editquote" value="[24,2]">Two</option>    
</select>   
</td>   
<tr>    
<td>    
<input type="submit" value="Send" class="mybutton"> 
</td>   
</tr>   
</table>    
</form> 

I selected option One and submitted the form.
Here is the result from the cakePHP built-in function, Debug()

Array
(
    [Test] => Array
        (
            [number] => [29,1]
        )

)

I tried using the following code to get the two numbers from the data (i.e. 29 and 1 in this example) but failed to do it

$myData=$this->data;
$myData['Test']['number'];  // [29, 1]

What should I do to get the two numbers separately?

+1  A: 

You could try this with PHP explode.

$numbers = explode(',', trim($myData['Test']['number'], '[]'));
$numbers[0]; //29
$numbers[1]; //1
Oscar
Updated with trim() also, although it might be easier to get rid of the [] in the source data?
Oscar
thank you for the quick help, Oscar.