Multiple array to PHP Object -
i'm struggeling few ours fugure out how this. have array this:
array (size=2) 0 => array (size=14) 'nr comanda' => string '251729' (length=6) 'descriere' => string 'so_dk35' (length=7) 'cod articol' => string '77a.02.03' (length=9) 'pack sscc' => string '012345000168970576' (length=18) 'pack greutate' => string '12.04' (length=5) 'pack tare' => string '0.49' (length=4) 'pack gross' => string '12.53' (length=5) 'pack nominal' => string '12.04' (length=5) 'lot' => string '4150' (length=4) 'data expirare' => string '8/30/2014' (length=9) 'data productie' => string '5/30/2014' (length=9) 'palet sscc' => string '212345000011125386' (length=18) 'palet tare' => string '27' (length=2) 'data fifo' => string '6/30/2014' (length=9) 1 => array (size=14) .....
and need have each value in php object this:
object(entrieslist)[5] public 'id' => null public 'nr_comanda' => null public 'descriere' => null public 'cod_articol' => null public 'pack_sscc' => null public 'pack_greutate' => null public 'pack_tare' => null public 'pack_gross' => null public 'pack_nominal' => null public 'lot' => null public 'data_expirare' => null public 'data_productie' => null public 'palet_sscc' => null public 'palet_tare' => null public 'data_fifo' => null
could please me php code? in advance.
for sake of answer, here goes:
$result = array(); foreach($arrays $array) {//your initial array $obj = new entrieslist; foreach($array $key=>$data) { $obj->{str_replace(' ',"_",strtolower($key))} = $data;//convert key lower , replace space underscore } $result[] = $obj; }
Comments
Post a Comment