2010-07-16 44 views
0

我正在學習cakePHP 1.26。
從cakePHP中提交表單中檢索一些數組數據

我有一個HTML選擇標籤,像這樣一些選擇:

<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的結果內置函數,調試()

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

) 

我嘗試使用下面的代碼從數據(即在本例中29和1)得到的兩個數字,但未能做它

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

我應該怎麼做才能分別得到兩個數字?

回答

1

你可以試試PHP explode

$numbers = explode(',', trim($myData['Test']['number'], '[]')); 
$numbers[0]; //29 
$numbers[1]; //1 
+0

用trim()也更新了,雖然它可能更容易擺脫源數據中的[]嗎? – Oscar 2010-07-16 16:09:40

+0

謝謝你的快速幫助,奧斯卡。 – user327712 2010-07-16 17:06:07