tags:

views:

41

answers:

2

Possible Duplicate:
How do i Loop through the hidden field items and put in Session using PHP

I have a hidden Field which contains this format which contains the Set of rows separated by ';'(semicolon) and each row contains some columns name separated by ':' (colon) and each column value separated by ',' (comma) so my format would be ENO:123,ENAME:XYZ,SAL:1200; ENO:598,ENAME:AIR,SAL:1300; which is what stored in hidden field

So How do i grab each column such as ENO ,ENAME and SAL their values for any number of rows written to hidden field so i have my own custom session function where i can set the key and value .So on looping the values I should be able to put MyCustomSessionFunction('ENAME',??????).How do i fill this .

I did not get Proper Replies Earlier .can anyone please help me

   $hiddenformat  =  $_POST['hiddenfield'];



   string(80) "ENO:1000,ENAME:B,SAL:10;ENO:1000,ENAME:S,SAL:100;"

when i vardump($hiddenformat) I am getting the above format .How do i explode and loop and assign each value to my custom session function

     foreach( $outer_array as $outer_key => $inner_array ) 
   {
     foreach( $inner_array as $key => $value ) 
     {

     }
   }
+3  A: 
$hiddenformat = $_POST['hiddenfield'];
$parts = explode(',', $hiddenformat);

foreach($parts as $part) {
    $bits = explode(':', $part);
    ...
}

Given a $hiddenformat of ENO:1000,ENAME:B,SAL:..., the first explode will split the line at every comma, giving you a $parts array that looks like:

$parts = array(
    0 => 'ENO:1000',
    1 => 'ENAME:B',
    2 => 'SAL:.....
);

Yuu use foreach to loop over this $parts array, and split the $part at every colon (:). So at each stage, $bits will look like:

$bits = array(
    0 => 'ENO',
    1 => '1000'
)

and then on the next iteration will

$bits = array(
    0 => 'ENAME',
    1 => 'B'
)

and so on. What you do with those individual chunks is up to you.

And yes, this was all present in the answers of the other questions. You just had to do a bit of work to put it all together.

Marc B
A: 

Yeah, it was. It's just to say that around that, you have to explode() by ";" and in the loop use Marc's code, since there are multiple Sets of data in the string

Tobi