Skip to main content

How can i store the values of array_count_values in array of object?



i have array like below which is sorted by array_count_values function,







Array

(

[Session #1: Tues May 31st - Fri June 10th (1-5:30PM)#1 only: 1pmADV] => 3

[Session #2: Tues June 14th - Fri June 24th (9-2:00PM)#1 only: 2pmADV] => 2

[Session #4: Tues July 12th - Fri July 22nd (9-2:00PM)#1 only: 1:30pmADV] => 2



)







i need to convert this array into array of object like below,







stdClass Object

(

[Itemname] => Session #1: Tues May 31st - Fri June 10th (1-5:30PM)#1 only: 1pmADV

[Quantity] => 3

)



stdClass Object

(

[Itemname] => Session #2: Tues June 14th - Fri June 24th (9-2:00PM)#1 only: 2pmADV

[Quantity] => 2

)

stdClass Object

(

[Itemname] => Session #4: Tues July 12th - Fri July 22nd (9-2:00PM)#1 only: 1:30pmADV

[Quantity] => 2

)







how can i do this?


Comments

  1. $arrayOfObjects = array();
    foreach ($values as $Itemname => $Quantity) {
    $arrayOfObjects[] = (object)compact('Itemname', 'Quantity');
    }

    ReplyDelete
  2. Something like this?:

    foreach($array as $key => $value){
    $object = new stdClass;
    $object->Itemname = $key;
    $object->Quantity = $value;
    print_r($object);
    }

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?