php - How do I access each value in array? -
i have attempted numerous times trying access each value in array. array contains database results retrieved select query.
$query = db::getinstance()->query("select orderstatus customerorders"); foreach ($query->results() $orderered) { $result_array = array($orderered); //print_r($result_array); $orderdata = array_map(function ($object) { return $object->orderstatus; }, $result_array); $test = json_decode(json_encode($result_array), true); $orvalue = serialize($test); $orvalue2 = unserialize($orvalue); $ordervaluenew = call_user_func_array('array_merge', $orvalue2); print_r($ordervaluenew);//debug }//close foreach loop
result prints are:
array ( [orderstatus] => 0 ) array ( [orderstatus] => 0 ) array ( [orderstatus] => 0 ) array ( [orderstatus] => 1 ) array ( [orderstatus] => 1 )
what you're doing should work retrieve each row, if want access orderstatus
value, can result array:
foreach ($result_array $resultrow) { echo $resultrow['orderstatus']; }
that should work, if that's mean. if want access orderstatus
value in first loop, can refer $row['orderstatus']
. or, if select *
in query , want go through values query, can make loop foreach ($row $column => value) { ... }