• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get to split the select value Question

#1
On my select drop down value I have it producing some thing like

Code:
<option value="codepen/4">Codepen RSS Feed > Home Page</option>

And code pen is "code" and 4 is id.

My question is how on my function could I be able to get the name and id seperate 

PHP Code:
foreach ($layout_data['layout_module'] as $layout_module) {
$split_input $layout_module['code'];

$code $split_input[0]; // should get name
$module_id $split_input[1]; // Should get id

$data_2 = array(
 
  'module_id' => $module_id,
 
  'code' => $code,
 
  'position_id' => $layout_module['position'],
 
  'sort_order' => (int)$layout_module['sort_order']
);



Any suggestions thank you.

Update I have tried now explode() seems to work have I got it correct


PHP Code:
foreach ($layout_data['layout_module'] as $layout_module) {
$split_input explode("/"$layout_module['code']);

$code $split_input[0];
$module_id $split_input[1];

$data_2 = array(
   
'module_id' => $module_id,
   
'code' => $code,
   
'position_id' => $layout_module['position'],
   
'sort_order' => (int)$layout_module['sort_order']
);

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#2
(01-15-2016, 05:16 PM)wolfgang1983 Wrote: On my select drop down value I have it producing some thing like

Code:
<option value="codepen/4">Codepen RSS Feed > Home Page</option>

And code pen is "code" and 4 is id.

My question is how on my function could I be able to get the name and id seperate 


Try this:
Code:
echo '<br />$val => ',
    $val = $val = 'codepen/4';     // codepen/4

echo '<br />';
echo '<br />$code => ',
    $code = strstr($val, '/', true);     // codepen
echo '<br />$tmp => ',
    $tmp = strstr($val, '/', false);     // /4
echo '<br />$module_id => ',
    $module_id = substr($tmp, 1);     // /4
Output:

$val => codepen/4

$code => codepen
$tmp => /4
$module_id => 4
download and make your system directory strict
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.