I'm getting strange behavior of array. I am getting an array with duplicate keys. I checked that this is due to the Datatype of the keys. How can i make it unique. This is the array:
Array
(
[1811258] => stdClass Object
(
[status] => true
[count] => 1
[price] => 2501
[attributes] =>
[groupid] => 2400
[subgroupid] => bux_364905
[desc] => GE Refrigerator - Side by Side GC5SHEXNQ..
[id] => 1811258
)
[1812193] => stdClass Object
(
[status] => true
[count] => 1
[price] => 293
[attributes] =>
[groupid] => 2410
[subgroupid] => 0
[desc] => STAINLESS STEEL DOUBLE BOWL - 20 GAUGE
[id] => 1812193
)
[1811258] => stdClass Object
(
[status] => 1
[count] => 1
[price] => 2501
[attributes] =>
[groupid] => 2400
[subgroupid] => bux_364905
[desc] => GE Refrigerator - Side by Side GC5SHEXNQ..
[id] => 1811258
)
[1852936] => stdClass Object
(
[status] => 1
[count] => 1
[price] => 525
[attributes] =>
[groupid] => 2489
[subgroupid] => 0
[desc] =>
[id] => 1852936
)
[1812193] => stdClass Object
(
[status] => 1
[count] => 1
[price] => 293
[attributes] =>
[groupid] => 2410
[subgroupid] => 0
[desc] => STAINLESS STEEL DOUBLE BOWL - 20 GAUGE
[id] => 1812193
)
)
I have tried array_key_exists()
function to check:
$saved=(array)json_decode($reviewdata->options);
foreach($optioncodes as $key=>$optioncode){
$option=$wpdb->get_row("SELECT * from {$prefix}builder_phaseplanoption where OptionCode='{$optioncode}' and SubdivisioNID='{$subdivision}'");
if($option){
if(array_key_exists($option->ID,$saved))
$saved[$option->ID]=(object)array('status'=>true,'count'=>1,'price'=>$option->UnitPrice,'attributes'=>'','groupid'=>$option->OptionGroupID,'subgroupid'=>$option->Sub_OptionGroupID,'desc'=>$option->OptionLongDesc,'id'=>$option->ID);
}
}
But no effect.I also tried to change the data type.Like this
$optid=(string)$option->ID; // now this shoud string but no effect
$saved[$optid]=(object)array('status'=>true,'count'=>1,'price'=>$option->UnitPrice,'attributes'=>'','groupid'=>$option->OptionGroupID,'subgroupid'=>$option->Sub_OptionGroupID,'desc'=>$option->OptionLongDesc,'id'=>$option->ID);
I know this is due to the problem that keys in the saved array are strings while the new keys are numbers. How can i convert them to the same type.
Thanks in advance.