Utilizo esta class para ese tipo de cosas
Código PHP:
<?php
class VAL{
const API = 1.0;
const VER = 1.0;
const SISTEM = "CFX-V2";
public static $param = array();
public static function parser($param, $equality="=", $delimiter="|", $escape="\\"){
if( is_array($param) ) return $param;
if(substr($param,-1,1) == $delimiter)$param = substr($param, 0, -1);
$d='[d:'.ord($delimiter).']';
$param=str_replace($escape.$delimiter,$d,$param);
$param=explode($delimiter,$param);
$ar=array();
foreach($param as $r){
$r= str_replace($d,$delimiter,$r);
$r= explode($equality,$r,2);
if(count($r)==2){
$r[0]=preg_replace('/\n+/', "", trim($r[0]));
$r[1]=self::parser($r[1], $equality, $delimiter, $escape);
$ar[$r[0]]=$r[1];
}else return implode($delimiter,$param);
}
return $ar;
}
public static function implode($param, $equality="=", $delimiter="|", $escape="\\"){
if( !is_array($param) ) return $param;
$str = '';
foreach($param as $key => $val){
$c=true;
if(is_array($val))$val=self::implode($val, $equality, $delimiter, $escape);
$val = str_replace( $delimiter, $escape.$delimiter, $val);
$str .=$key . $equality . $val . $delimiter;
}
if($c)$str = substr($str,0,-1);
return $str;
}
public static function extend($default, $param, $parser=false){
if( $parser) $param = self::parser( $param );
if( !is_array($default)) return $default;
foreach($default as $key => $val ){
if( isset($param[$key]) ) $default[$key] = is_array( $default[$key] )? self::extend( $default[$key],$param[$key],$parser ) : $param[$key] ;
}
return $default;
}
public static function set($ruta, $value, $param=NULL){
$n=explode('/',$ruta);
is_array($param)?$t=&$param : $t=&self::$param;
for($i = 0; $i < count($n); $i++){
($n[$i] == '')?$t=&$t[]:$t=&$t[$n[$i]];
}
$t=$value;
return self::$param;
}
public static function get($ruta, $param=NULL){
$n=explode('/',$ruta);
$t=is_array($param)?$param:self::$param;
for($i = 0; $i < count($n); $i++){
$t=$t[$n[$i]];
}
return $t;
}
}
?>
Código PHP:
$stringProductos = "3,7;27,2;1,4;12,10;";
$stringProductos = VAL::parser($stringProductos,',',';');
print_r($stringProductos);
$stringProductos = VAL::implode($stringProductos,',',';');
print_r($stringProductos);
en tu caso
Código PHP:
$stringProductos = "3,7;27,2;1,4;12,10;";
$stringProductos = VAL::parser($stringProductos,',',';');
print_r($stringProductos);
$newArray=array();
foreach($stringProductos as $key => $val){
$newArray[]=array($key => $val);
}
print_r($newArray);