0

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

1

You could try this with PHP explode.

$numbers = explode(',', trim($myData['Test']['number'], '[]'));
$numbers[0]; //29
$numbers[1]; //1
Sign up to request clarification or add additional context in comments.

1 Comment

Updated with trim() also, although it might be easier to get rid of the [] in the source data?

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.