0

我正在学习 cakePHP 1.26。

我有一个 HTML Select 标记,其中包含一些选项,如下所示:

<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> 

我选择了选项一并提交了表格。
这是 cakePHP 内置函数 Debug() 的结果

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

)

我尝试使用以下代码从数据中获取两个数字(即本例中的 29 和 1)但未能做到

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

我应该怎么做才能分别获得这两个数字?

4

1 回答 1

1

你可以用PHP explode试试这个。

$numbers = explode(',', trim($myData['Test']['number'], '[]'));
$numbers[0]; //29
$numbers[1]; //1
于 2010-07-16T16:05:12.920 回答