fork(2) download
  1. <?php
  2.  
  3. $SQL_RE=array(
  4. "COUNT" => "5",
  5. "FORM" => "1&#painting",
  6. "SCHOOL" => "1&#German",
  7. "LOCATION" => "1&#Alte Pinakothek, Munich##2&#Kunsthistorisches Museum, Vienna##3&#Private collection",
  8. "TIMEFRAME" => "1&#1601-1650",
  9. "TYPE" => "1&#mythological##2&#genre##3&#portrait");
  10.  
  11. print_r($SQL_RE);
  12.  
  13. //MY FRANKEISTEIN FUNCTION
  14. /* $row_array=array();
  15.   foreach ($SQL_RE as $key => $row_el){
  16.   $expand = explode('##', $row_el);
  17.   $expand_NEW = array();
  18.   foreach($expand as $deepkey){
  19.   $expand_t=explode('&#', $deepkey);
  20.   if(count($expand_t)>1){
  21.   $temp=array(
  22.   "ID" => (int)$expand_t[0],
  23.   "VALUE" => (string)$expand_t[1]
  24.   );
  25.   array_push($expand_NEW, $temp) ;
  26.   }else{
  27.   array_push($expand_NEW, $expand_t) ;
  28.   }
  29.   }
  30.   if(count($expand_NEW[0])==1) $expand_NEW=$row_el;
  31.   $row_array[$key] = $expand_NEW;
  32.   }
  33.   print_r($row_array);
  34. */
  35.  
  36. //PRETTY PRINCESS, ALMOST CORRECT
  37. foreach ($SQL_RE as $key => $row_el){
  38. $val = array_map(function($v) { return explode('&#', $v); }, explode('##', $row_el));
  39. $data_arr[$key] = $val;
  40. }
  41. print_r($data_arr);
  42.  
Success #stdin #stdout 0.01s 24328KB
stdin
Standard input is empty
stdout
Array
(
    [COUNT] => 5
    [FORM] => 1&#painting
    [SCHOOL] => 1&#German
    [LOCATION] => 1&#Alte Pinakothek, Munich##2&#Kunsthistorisches Museum, Vienna##3&#Private collection
    [TIMEFRAME] => 1&#1601-1650
    [TYPE] => 1&#mythological##2&#genre##3&#portrait
)
Array
(
    [COUNT] => Array
        (
            [0] => Array
                (
                    [0] => 5
                )

        )

    [FORM] => Array
        (
            [0] => Array
                (
                    [0] => 1
                    [1] => painting
                )

        )

    [SCHOOL] => Array
        (
            [0] => Array
                (
                    [0] => 1
                    [1] => German
                )

        )

    [LOCATION] => Array
        (
            [0] => Array
                (
                    [0] => 1
                    [1] => Alte Pinakothek, Munich
                )

            [1] => Array
                (
                    [0] => 2
                    [1] => Kunsthistorisches Museum, Vienna
                )

            [2] => Array
                (
                    [0] => 3
                    [1] => Private collection
                )

        )

    [TIMEFRAME] => Array
        (
            [0] => Array
                (
                    [0] => 1
                    [1] => 1601-1650
                )

        )

    [TYPE] => Array
        (
            [0] => Array
                (
                    [0] => 1
                    [1] => mythological
                )

            [1] => Array
                (
                    [0] => 2
                    [1] => genre
                )

            [2] => Array
                (
                    [0] => 3
                    [1] => portrait
                )

        )

)