In my code I want to access a property of an object in PHP using its index value, I can access it using the name but not using the index value:
I can do it like this :
foreach($object as $row)
{
echo $row['type'];
}
I want something like this:
foreach($object as $row)
{
echo $row[0];
}
Try this:
$arr = array_values((array) $object);
foreach ($arr as $row)
{
echo $row[0];
}
Updated:
I think, in your case, you have to convert into array each row, like this:
foreach ($object as $row)
{
$row = array_values((array) $row);
echo $row[0];
}
Try this:
$object = array_values($object);
foreach($object as $row)
{
echo $row[0];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.