Forum Moderators: coopster
<?php
function do_that($array){
$counter = 0;
foreach($array as $key => $row){
if($array_type=='object'){
$id = $array->id;
}else{
$id = $array[$counter];
}
//do stuff with id
$counter = $counter+1;
}
}
?>
class testobj {
function testobj() {
$this->id = 0;
$this->data = 1;
}
}
function check($input){
echo 'Is this an Array? <b>' . (is_array($input)?'true':'false') . '</b><br />';
if( is_object($input) ) {
// convert to array
$input = (array)$input;
}
print_r($input);
}
$to = new testobj;
check($to);
$to = array(1,2,3);
check($to);
exit();