If its possible to access the 'entry_id
' data in a foreach
loop as below, if I know there is only one item, is there a better way to access it?
$arr = array();
foreach( $order->items as $item ) {
$arr[] = $item->entry_id;
}
If its possible to access the 'entry_id
' data in a foreach
loop as below, if I know there is only one item, is there a better way to access it?
$arr = array();
foreach( $order->items as $item ) {
$arr[] = $item->entry_id;
}
If order->items is no-associative array and its only 1 element, you can access it this way:
echo $order->items[0]->entry_id;
But more safe will be check how many items in array:
if(count($order->items) > 0)
echo $order->items[0]->entry_id;