-3

I'm struggeling for a few ours to fugure out how to do this. I have an array like 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 I need to have each value in an PHP Object like 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 you please help me with the php code? Thanks in advance.

lartisan
  • 5
  • 4
  • 2
    There's no code writing service here - include your attempts, the current output, and details of any errors you see – Clive Jun 27 '14 at 11:42
  • 1
    Have a look at http://stackoverflow.com/questions/1869091/convert-array-to-object-php/9895734#9895734 – techgyani Jun 27 '14 at 11:45
  • Your question gives your answer. Create class name with EntriesList having all params your required in that object. Then either by getter/setter or using public assign values to those variable and get class in object. – Savan Koradia Jun 27 '14 at 11:59

1 Answers1

0

For the sake of an answer, here it goes:

$result = array();
foreach($arrays as $array)
{//your initial array
    $obj = new EntriesList;
    foreach($array as $key=>$data)
    {
        $obj->{str_replace(' ',"_",strtolower($key))} = $data;//convert the key to lower and replace space with underscore

    }
    $result[] = $obj;
} 
ka_lin
  • 9,329
  • 6
  • 35
  • 56