Removing a StdClass Object in an multidimensional array [PHP] -
i'm looking convert array, i'm doing db associated array , reason have array within array key "region" , object value. i've tried unset , doesnt seem work!
if can issue, that'll massive help!
php code:
$sql = $db->get_records_sql('select sc.name `branch`, c.name `region` mdl_auth_crowd_tag_sub_category sc join mdl_auth_crowd_tag_category c on sc.catid = c.id'); echo "</br>"; $array = $fields = array(); $i = 0; if ($sql) { $row = $sql; foreach ($row $k=>$value) { if($k == 1){ $array[$i]['branch'] = $value; } else { $array[$i]['region'] = $value; } $i++; } } var_dump($array);
my current array output straight records:
array(3) { [0]=> array(1) { ["region"]=> object(stdclass)#634 (2) { ["branch"]=> string(6) "london" ["region"]=> string(10) "south east" } } [1]=> array(1) { ["region"]=> object(stdclass)#637 (2) { ["branch"]=> string(8) "plymouth" ["region"]=> string(10) "south west" } } [2]=> array(1) { ["region"]=> object(stdclass)#647 (2) { ["branch"]=> string(7) "preston" ["region"]=> string(10) "north west" } } }
i want output, , remove object std array , replace array showing how many values within below!
array(3) { [0]=> array(2) { ["branch"]=> string(6) "london" ["region"]=> string(10) "south east" } } [1]=> array(2) { ["branch"]=> string(8) "plymouth" ["region"]=> string(10) "south west" } } [2]=> array(2) { ["branch"]=> string(7) "preston" ["region"]=> string(10) "north west" } } }
Comments
Post a Comment