Código PHP:
//Dado un string del tipo:
$stringProductos = "3,7;27,2;1,4;12,10;";
//Quiero que acabe metido en un array de esta forma:
$array = array(
array(3=>7),
array(27=>2),
array(1=>4),
array(12=>10)
)
//Para ello he intentado:
$lines = explode(";", $stringProductos);
$array = array();
foreach ( $lines as $line ){
$values = explode(',', $line);
$array[$values[0]] = array($values[0] , $values[1]);
}
print_r($array);
Y he conseguido el error:
Notice: Undefined offset: 1 in C:\xampp\htdocs\Dropbox\proyectoJaviOscar\htdocs\U ntitled-1.php on line 38
Y esto:
Array ( [3] => Array ( [0] => 3 [1] => 7 ) [27] => Array ( [0] => 27 [1] => 2 ) [1] => Array ( [0] => 1 [1] => 4 ) [12] => Array ( [0] => 12 [1] => 10 ) [5] => Array ( [0] => 5 [1] => 2 ) [6] => Array ( [0] => 6 [1] => 1 ) [9] => Array ( [0] => 9 [1] => 1 ) [26] => Array ( [0] => 26 [1] => 1 ) [29] => Array ( [0] => 29 [1] => 1 ) [31] => Array ( [0] => 31 [1] => 1 ) [] => Array ( [0] => [1] => ) )
Que creeis que debo de cambiar???? Graciass de antemano!!!